Registry / web-framework / server-router

server-router

JSON →
library6.1.0jsnpmunverified

server-router is a Node.js HTTP router designed for streaming servers, leveraging a radix-trie data structure for high-performance route matching. It provides a concise API for defining routes with HTTP methods, including support for route parameters and wildcard paths. The current stable version is 6.1.0. Given its "experimental" stability rating as indicated by its documentation, its release cadence is irregular and breaking changes are possible without strict adherence to semantic versioning. It differentiates itself by focusing on server-side streaming applications and efficient routing, contrasting with client-side alternatives like nanorouter or more general-purpose routing solutions, by offering a low-level, performant foundation. It is suitable for applications where minimal overhead and direct HTTP stream handling are critical.

npm install server-router
INSTALL
IMPORT
SIG · SERVER-ROUTER
S
server-router
web-frameworkjavascriptv6.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

serverRouter
const serverRouter = require('server-router')
import serverRouter from 'server-router'
Package primarily uses CommonJS `require` syntax. Direct ESM imports are not supported without transpilation or a wrapper.

Demonstrates setting up a basic HTTP server with multiple routes using GET, PUT, and combined methods, including a 404 handler and dynamic parameter extraction.

var serverRouter = require('server-router') var http = require('http') var router = serverRouter({ default: '/404' }) router.route('GET', '/hello', function (req, res, params) { res.end('hello world') }) router.route('PUT', '/hello/:name', function (req, res, params) { res.end('hi there ' + params.name) }) router.route(['GET', 'POST'], '/json', function (req, res, params) { res.setHeader('Content-Type', 'application/json') res.end(JSON.stringify({ message: 'Dynamic JSON response', params })) }) router.route('', '/404', function (req, res, params) { res.statusCode = 404 res.end('404 Not Found') }) const server = http.createServer(router.start()) const PORT = process.env.PORT ?? 3000 server.listen(PORT, () => { console.log(`Server listening on http://localhost:${PORT}`) console.log('Try visiting: http://localhost:3000/hello') console.log('Try visiting: http://localhost:3000/hello/Alice (e.g., via curl -X PUT)') console.log('Try visiting: http://localhost:3000/json') console.log('Try visiting: http://localhost:3000/nonexistent') })
Debug
Known issues
breakingThe package is currently marked as 'experimental' stability. This implies that the API may change without strict adherence to semantic versioning, and breaking changes can occur even in minor or patch releases.
fix
Monitor GitHub repository and npm releases for potential changes when upgrading. Consider locking to specific versions or thorough testing before deploying to production.
affects: >=1.0.0
gotchaThe README example for setting a 404 status (`res.status = 404`) is incorrect for Node.js's native `http.ServerResponse` object. The correct property to set the HTTP status code is `res.statusCode`.
fix
Always use `res.statusCode = <CODE>` to set the HTTP status, e.g., `res.statusCode = 404;`.
affects: >=1.0.0
gotchaThis package is designed for CommonJS (CJS) environments and uses `require()`. While Node.js has ESM support, `server-router` does not officially support direct `import` statements without a transpilation step.
fix
Ensure your project uses `require()` for importing `server-router` or configure a build step (e.g., with Babel or TypeScript) to transpile ESM imports to CJS.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'server-router'
The 'server-router' package has not been installed or is not resolvable in the current project's `node_modules`.
fix
Run `npm install server-router` or `yarn add server-router` in your project directory.
TypeError: res.status is not a function
Attempting to set the HTTP status code using `res.status = <CODE>` instead of the correct `res.statusCode = <CODE>` on a native Node.js `http.ServerResponse` object.
fix
Change `res.status = 404` to `res.statusCode = 404`.
Upgrade
Version history
6.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
14
OpenAI (training)
1
Resources
server-router — npm install server-router · libregistry