Gathering detailed insights and metrics for @zibuthe7j11/commodi-odit-tenetur
Gathering detailed insights and metrics for @zibuthe7j11/commodi-odit-tenetur
Gathering detailed insights and metrics for @zibuthe7j11/commodi-odit-tenetur
Gathering detailed insights and metrics for @zibuthe7j11/commodi-odit-tenetur
npm install @zibuthe7j11/commodi-odit-tenetur
Typescript
Module System
Node Version
NPM Version
JavaScript (100%)
Total Downloads
127
Last Day
2
Last Week
2
Last Month
6
Last Year
127
3 Commits
1 Branches
Latest Version
1.0.0
Package Id
@zibuthe7j11/commodi-odit-tenetur@1.0.0
Unpacked Size
30.30 kB
Size
11.05 kB
File Count
10
NPM Version
10.5.0
Node Version
20.12.2
Publised On
27 Apr 2024
Cumulative downloads
Total Downloads
Last day
0%
2
Compared to previous day
Last week
100%
2
Compared to previous week
Last month
-45.5%
6
Compared to previous month
Last year
0%
127
Compared to previous year
A small but effective node based server for development sites, customizable live reloading, and websocket support built-in. You should consider using NSS if:
:heavy_check_mark: You want to add live reloading to the development process of a static site.
:heavy_check_mark: You want easy two-way communication from the back-end and front-end of your development site or web based application with built-in WebSockets ready for use.
:heavy_check_mark: You want more fine grained control over the whole live reloading process.
:heavy_check_mark: You want to easily test your development site on multiple devices; must be on the same LAN.
:heavy_check_mark: You want to easily setup a LAN application for educational purposes or other development; must be on the same LAN, please consider security implications.
:heavy_check_mark: You want to easily setup a web based application that leverages the browser as your apps GUI but can interact with system data via websocket; great for internal applications.
Node Simple Server (NSS) can be manually incorporated into your development process/ application. Extract the nss
folder from the latest release and then import
the server module into your code, similar to:
1import NodeSimpleServer from './nss.js';
You can install and use NSS locally in a project with:
1# As a normal dependency: 2npm install @zibuthe7j11/commodi-odit-tenetur 3 4# or as a development dependency: 5npm install @zibuthe7j11/commodi-odit-tenetur --save-dev
Depending on how you use and incorporate NSS into your project will determine the best dependency strategy to use.
You can install and use NSS globally with:
1npm install --global @zibuthe7j11/commodi-odit-tenetur
NSS is designed to be controlled and/or wrapped by another application. The bare minimum code needed to use NSS in your application is:
1/** 2 * If you want/need to import NSS from a manual install replace the below import statement with: 3 * 4 * import NodeSimpleServer from './nss.js'; 5 * 6 * NOTE: Manual installs must include the handlers directory one directory higher than NSS. 7 */ 8import NodeSimpleServer from '@zibuthe7j11/commodi-odit-tenetur' 9import { fileURLToPath } from 'url'; 10import path from 'path' 11 12// This is needed for ES modules. 13const __filename = fileURLToPath(import.meta.url); 14const __dirname = path.dirname(__filename); 15 16// Determine what directory to watch for changes; defaults to project root. 17const websiteRoot = __dirname; 18 19// Build a bare minimum server options object. 20const serverOptions = { 21 root: websiteRoot 22}; 23 24// Get a new instance of NSS. 25const Server = new NodeSimpleServer(serverOptions); 26 27// A bare minimum callback to handle most development changes. 28function watcherCallback(event, path, extension) { 29 if (extension === 'css') { 30 Server.reloadAllStyles(); 31 return; 32 } 33 if (extension === 'js') { 34 /** 35 * NOTE: This is a heavy request to use if your site loads resources from 36 * other sites such as images, databases, or API calls. Consider a better 37 * approach in these cases such as throttling. 38 */ 39 Server.reloadAllPages(); 40 return; 41 } 42 if (event === 'change') { 43 Server.reloadSinglePage(path); 44 } 45} 46 47/** 48 * A bare minimum callback to handle all websocket messages from the frontend. By 49 * default NSS registers and responds to WebSockets by the web pages pathname. In 50 * a web page: 51 * 52 * NSS_WS.send([string|int|bool|object]) // Pathname lookup will be used. 53 */ 54function websocketCallback(messageObject, pageId) { 55 // Interpret and do what you need to with the message: 56 const datatype = messageObject.type 57 const data = messageObject.data; 58 console.log(`Received ${datatype} data from page ${pageId}: ${data}`) 59 60 // Respond to the page that sent the message if you like: 61 Server.message(pageId, 'Messaged received!'); 62} 63Server.addWebsocketCallback('.*', websocketCallback); 64 65/** 66 * A bare minimum callback to handle all websocket messages from the frontend. 67 * This is a special example that registers a specific route to listen for. In a 68 * web page: 69 * 70 * NSS_WS.send([string|int|bool|object], [route string]) // Route lookup will be used. 71 */ 72function websocketCallback(messageObject, pageId) { 73 // Interpret and do what you need to with the message: 74 const datatype = messageObject.type 75 const data = messageObject.data; 76 console.log(`Route received ${datatype} data from page ${pageId}: ${data}`) 77 78 // Respond to the page that sent the message if you like: 79 Server.message(pageId, 'Route specific messaged received!'); 80} 81Server.addWebsocketCallback('api/search', websocketCallback); 82 83// A bare minimum watcher options object; use for development, omit for production. 84const watcherOptions = { 85 events: { 86 all: watcherCallback, // Just send everything to a single function. 87 }, 88}; 89 90// Start the server. 91Server.start(); 92 93// Watch the current directory for changes; use for development, omit for production. 94Server.watch(websiteRoot, watcherOptions);
The options
object required by the watch
method must include an events
property with at least one watched event. The demo code above used all
to capture any event. This object takes a lot of settings and is explained below in the Watch Options table.
NSS uses process.cwd()
as the live servers root if omitted and is pre-configured with several additional default settings. You can change these by providing your own options
object when instantiating the server. How this looks in code is shown below, the following table Server Options explains all available options.
1// Make your options object. 2const options = {...}; 3 4// Get a new instance of NSS and pass in the options. 5const Server = new NodeSimpleServer(options);
Note: If you set options.root
to a different location than the current directory, you should usually provide the same path or a child path of this path, when you instantiate Server.watch
.
NOTE: This is an advanced setting and should rarely need to be altered.
NOTE: Even if you are not watching for any events this loads a full NSS developer websocket into all pages on the server address. Disabling this will load only a simplified NSS websocket.
all
, add
, addDir
, change
, unlink
, unlinkDir
, ready
, raw
, error
. Any property set on events
should point to a callback function that will handle that event.true
will not fire add
or addDir
events when the files/directories are first being discovered.false
, only the symlinks themselves will be watched for changes instead of following the link references and bubbling events through the link's path.paths
are to be derived. Paths emitted with events will be relative to this path and will use only forward slashes (/) on all operating systems.false
.fs.Stats
object that may get passed with add
, addDir
, and change
events, set this to true
to ensure it is provided even in cases where it wasn't already available from the underlying watch events.-Indicates whether to watch files that don't have read permissions if possible. If watching fails due to EPERM
or EACCES
with this set to true
, the errors will be suppressed silently.
Most of the Watch Object Options are directly from chokidar which is being used to handle the file monitoring. You may want to visit the chokidar repo for more information. Please note that event paths are altered by NSS to only use forward slashes (/) on all operating systems.
With your new instance of NSS you can call any of the following public methods:
callback
) to receive messages from the front-end if the pages URL matches the pattern
.msg
) via WebSocket to the page that matches the pageId
, or send to a page or pages that match the pattern
.pattern
.pattern
.callback
function that was initially registered with the pattern
.callback
if present. Port
is meant to be an internal option for NSS only but you may specify a port number for NSS to use if you have strict requirements in your environment. NOTE: This is a blocking process and will keep any application that ran it alive until stopped gracefully or forcefully terminated. If you do not want this behavior for any reason you will need to call this in its own process.callback
if present.paths
) for changes previously registered with watch
.paths
) for changes and then callback to functions set in watchOptionsObject
that will respond to these changes.^ pattern
refers to either a RegExp
object or a string of text that represents a regular expression without surrounding slashes (/) or modifiers (g, i, etc.). If you provide a string make sure to correctly escape literal characters. In some instances pattern
can also be a string of text representing a page's unique ID. pattern
does not recognize glob patterns!
^^ paths
refers either to a string or array of strings. Paths to files, directories to be watched recursively, or glob patterns. Globs must not contain windows separators (\), because that's how they work by the standard — you'll need to replace them with forward slashes (/). For additional glob documentation, check out low-level library: picomatch.
The current changelog is here. All other changelogs are here.
NSS is an open source community supported project, if you would like to help please consider tackling an issue or making a donation to keep the project alive.
No vulnerabilities found.
No security vulnerabilities found.