
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
expressjs-route-mapper
Advanced tools
HTTP dynamic routing with Express.js
The motivation for this module is to provide a high-level abstraction of routes in express.js. It is written in JavaScript, and is 100% MIT licensed.
npm install expressjs-route-mapper --save
Method Scope Semantics
GET collection Retrieve all resources in a collection
GET resource Retrieve a single resource
HEAD collection Retrieve all resources in a collection (header only)
HEAD resource Retrieve a single resource (header only)
POST collection Create a new resource in a collection
PUT resource Update a resource
PATCH resource Update a resource
DELETE resource Delete a resource
COPY resource Clone/Copy of an existing resource.
PURGE resource pick out an object from the cache and discard
TRACE resource TRACE allows the client to see testing or diagnostic information.
OPTIONS any Return available HTTP methods and other options
Here is an example on how to use it:
express = require("express");
app = express();
require('expressjs-route-mapper').use(app);
app.routeMapper({
base: '/users/:user_id/tables/:table_id',
routes: {
'/stories': {
'get': function(req, res){ res.send('hello get'); },
'delete': function(req, res){ res.send('hello delete'); },
'put': function(req, res){ res.send('hello put'); },
'post': function(req, res){ res.send('hello post'); },
}
}
});
These are the routes that will get created with the code above:
Method URL
GET /users/:user_id/tables/:table_id/stories
POST /users/:user_id/tables/:table_id/stories
DELETE /users/:user_id/tables/:table_id/stories
PUT /users/:user_id/tables/:table_id/stories
Here we have route [IndexRoute] with before callback [IndexRoute.before] which run before the main route IndexRoute. This is useful for security check or validate a user before render the main route
express = require("express");
app = express();
require('expressjs-route-mapper').use(app);
IndexRoute = function(req, res){
return 'Hello World'
}
IndexRoute.before = function(req, res){
return 'Hello World'
}
app.routeMapper({
base: '/home',
routes:
'get': function(req, res, next){
res.send('Hello World');
}
});
Declare your root or home url with the base options:
app.routeMapper({
base: '/product',
routes: {
'get': function(req, res, next){
res.send('Hello World');
},
'/category':{
'get': function(req, res, next){
res.send('Hello World');
}
}
}
});
These are the routes that will get created with that method call:
Method URL
GET /product
GET /product/category
express = require("express");
app = express();
require('expressjs-route-mapper').use(app);
app.routeMapper({
routes: {
'/product': {
'get': function(req, res){
return "Hello World, I'm an http get method"
},
'post': function(req, res){
return "Hello World, I'm an http post method"
},
'/byId':{
'get': function(req, res){
return "my product id is 10"
},
'delete': function(req, res){
return "Hello World, I'm an http delete method"
},
}
}
}
});
These are the routes that will get created with that method call:
Method URL
GET /product
POST /product
GET /product/byId
Delete /product/byId
domain specific routes
express = require("express");
app = express();
require('expressjs-route-mapper').use(app);
myDomainServer = express();
myDomainServer.get('/', function(req, res){
res.send('hello one.lvh.me');
})
app.routeMapper({
host: 'one.lvh.me',
server: myDomainServer, //optional server
base: '/my-route',
routes: {
'get': function(req, res){ res.send('hello one.lvh.me/my-route'); },
}
});
app.routeMapper({
host: 'two.lvh.me',
base: '/your-route',
routes: {
'get': function(req, res){ res.send('hello two.lvh.me/your-route'); },
}
});
These are the routes that will get created with that method call:
Method URL Domain
GET /my-route http://one.lvh.me/my
GET /your-route http://your-domain/your-domain
lvh.me //domain www
www.lvh.me //sub-domain www
*.lvh.me //any sub-domain
Inspired by express.js examples
FAQs
HTTP dynamic routing with Express.js
We found that expressjs-route-mapper 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.