
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
A lean and mean web router for node.js.
It is available through npm:
npm install router
The router routes using the method and a pattern
var router = require('router').create();
router.get('/', function(request, response) {
response.writeHead(200);
response.end('hello index page');
});
router.listen(8080); // start the server on port 8080
If you want to grap a part of the path you can use capture groups in the pattern:
router.get('/{base}', function(request, response) {
var base = request.matches.base; // ex: if the path is /foo/bar, then base = foo
});
The capture patterns matches until the next /
or character present after the group
router.get('/{x}x{y}', function(request, response) {
// if the path was /200x200, then request.matches = {x:'200', y:'200'}
});
You can also use regular expressions and the related capture groups instead:
router.get(/^\/foo\/(\w+)/, function(request, response) {
var group = request.matches[1]; // if path is /foo/bar, then group is bar
});
Besides get
the avaiable methods are post
, put
, head
, del
, request
and upgrade
.
request
matches all the standard http methods and upgrade
is usually used for websockets.
FAQs
Simple middleware-style router
The npm package router receives a total of 1,107,820 weekly downloads. As such, router popularity was classified as popular.
We found that router demonstrated a not healthy version release cadence and project activity because the last version was released 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
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.