
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
express-routeloader
Advanced tools
This is originally a fork of Livedocs-routeloader. Some credit goes to Simon Mcmannus
Express-routeloader makes it easy to handle endpoints for your REST server.
Express-routeloader builds an express router from your ./routes
folder.
when given a directory structure like
routes
- groups.js
where groups is
exports.read = {
handler : function (req, res) {
res.send(200);
}
};
exports.create = {
handler : function (req, res) {
res.send(200);
}
};
Express-routeloader will create a router with the following routes:
POST /groups
GET /groups/:id
You can use multiple routers in the same project which is really useful for maintaining multiple versions of an api.
The routeloader works as a simple router of express:
'use strict';
var express = require('express'),
app = express(),
router = require('express-routeloader')({/* option */});
app.use(router);
app.listen(3000);
rootDir
: The directory containing your routes. Defaults to ./routes
logger
: Logging function. default : console.log
hideCRUD
: Should CRUD endpoints have the extentions be hidden.
GET assets/read/:id
becomes `GET assets/:id. Defaults to true.
verbMap
: Json object mapping filenames to default HTTP verbs. default :
{
"create": "POST",
"read": "GET",
"list" : "GET",
"search" : "GET",
"update": "PUT",
"delete": "DELETE"
}
prefix
: prefix for all loaded routes e.g. /api/v1/
.
this is very useful for maintaining multiple versions of an api.
routing endpoints are node modules that export a set of objects with a method handler
:
'use strict' // Ofc we are running strict!
exports.hello = {
handler :function (req, res, next) {
res.send('world');
}
};
You can overwrite default settings by adding properties to the exported object:
'use strict' // Ofc we are running strict!
exports.hello = {
url = '/different/route/to/:id',
method = 'PUT',
middleware = [func1, func2, func3],
handler : function (re, res, next) {
res.send('World');
}
};
Express-routeloader lets you use json-schema to validate the input to your endpoints. to add validation simply add the schema to the module.
'use strict' // Ofc we are running strict!
exports.hello = {
url = 'update/:id',
method : 'POST',
params = {
required : ['id'],
properties : {
handler : {
type : 'integer',
minimum : 0
}
}
},
query = {
properties : {
someOption : {
type : 'boolean'
}
}
},
body = {
properties : {
name : {
type : 'string',
maxLength : 80
}
}
},
handler : function (req, res, next) {
// do an update
res.send('world');
}
};
Express route validator supports promises. If a route handler returns a promise, routeloader with call res.send on promise resolution and next on rejection.
FAQs
Automatic routeloader for the express web framwork
We found that express-routeloader 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
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.