
Security News
Socket Releases Free Certified Patches for Critical vm2 Sandbox Escape
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.
@caboodle-tech/node-simple-server
Advanced tools
Node Simple Server (NSS): A small but effective node based server for development sites, customizable live reloading, and websocket support built-in.
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.
Like any other Node based application you can install NSS automatically with pnpm or npm and then reference it in your code. This is the recommended way to install and use NSS.
# Install using pnpm:
pnpm add @caboodle-tech/node-simple-server
# Or install using npm:
npm install @caboodle-tech/node-simple-server
Then use in your code with:
import NodeSimpleServer from '@caboodle-tech/node-simple-server';
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:
import NodeSimpleServer from './nss.js';
You can install and use NSS globally with:
pnpm install -g @caboodle-tech/node-simple-server
Depending on how you use and incorporate NSS into your project will determine the best dependency strategy to use.
NSS is designed to be controlled and/or wrapped by another application. The bare minimum code needed to use NSS in your application is:
/**
* If you want/need to import NSS from a manual install replace the below import statement with:
*
* import NodeSimpleServer from './nss.js';
*
* NOTE: Manual installs must include the handlers directory one directory higher than NSS.
*/
import NodeSimpleServer from '@caboodle-tech/node-simple-server'
import { fileURLToPath } from 'url';
import path from 'path'
// This is needed for ES modules.
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Determine what directory to watch for changes; defaults to project root.
const websiteRoot = __dirname;
// Build a bare minimum server options object.
const serverOptions = {
root: websiteRoot
};
// Get a new instance of NSS.
const Server = new NodeSimpleServer(serverOptions);
/**
* A bare minimum callback to handle most development changes. You register only for
* the events you need; unhandled events (e.g. unlink/unlinkDir if not listed) are ignored.
*/
const watcherCallback = (event, path, statsOrDetails) => {
const extension = statsOrDetails.ext;
if (extension === 'css') {
Server.reloadAllStyles();
return;
}
if (extension === 'js') {
/**
* NOTE: This is a heavy request to use if your site loads resources from
* other sites such as images, databases, or API calls. Consider a better
* approach in these cases such as throttling.
*/
Server.reloadAllPages();
return;
}
if (event === 'change') {
Server.reloadSinglePage(path);
}
// When a file or directory is removed, reload so the browser does not show stale content.
if (event === 'unlink' || event === 'unlinkDir') {
Server.reloadAllPages();
}
};
/**
* A bare minimum callback to handle all websocket messages from the frontend. By
* default NSS registers and responds to WebSockets by the web pages pathname. In
* a web page:
*
* NSS_WS.send([string|int|bool|object]) // Pathname lookup will be used.
*/
const websocketCallback = (messageObject, pageId) => {
const datatype = messageObject.type;
const data = messageObject.data;
console.log(`Received ${datatype} data from page ${pageId}: ${data}`);
Server.message(pageId, 'Message received!');
};
Server.addWebsocketCallback('.*', websocketCallback);
/**
* A bare minimum callback to handle all websocket messages from the frontend.
* This is a special example that registers a specific route to listen for. In a
* web page:
*
* NSS_WS.send([string|int|bool|object], [route string]) // Route lookup will be used.
*/
const websocketCallbackRoute = (messageObject, pageId) => {
const datatype = messageObject.type;
const data = messageObject.data;
console.log(`Route received ${datatype} data from page ${pageId}: ${data}`);
Server.message(pageId, 'Route specific message received!');
};
Server.addWebsocketCallback('api/search', websocketCallbackRoute);
/**
* Watcher options: the events you register are your intent. Only registered events
* are handled; others (e.g. unlink, unlinkDir) are ignored unless you add them.
*/
const watcherOptions = {
events: {
all: watcherCallback,
},
};
// Start the server.
Server.start();
// Watch the current directory for changes; use for development, omit for production.
Server.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. You express intent by which events you register: only those are handled; others are ignored. If your app has a build step (e.g. source → output), register for unlink and unlinkDir in events to react when files or directories are removed (e.g. to keep your output in sync). 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.
// Make your options object.
const options = {...};
// Get a new instance of NSS and pass in the options.
const 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. Only the events you register are handled; others are ignored. Use unlink and unlinkDir when you need to react to file or directory deletion (e.g. to sync your build output or trigger a reload).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.returnInstead to true.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. Set printAddresses to false if you want to hide or print the server address on your own.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.
FAQs
Node Simple Server (NSS): A small but effective node based server for development sites, customizable live reloading, and websocket support built-in.
We found that @caboodle-tech/node-simple-server demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
A critical vm2 sandbox escape can allow untrusted JavaScript to break isolation and execute commands on the host Node.js process.

Research
Five malicious NuGet packages impersonate Chinese .NET libraries to deploy a stealer targeting browser credentials, crypto wallets, SSH keys, and local files.

Security News
pnpm 11 turns on a 1-day Minimum Release Age and blocks exotic subdeps by default, adding safeguards against fast-moving supply chain attacks.