
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
express-router-handler
Advanced tools
An Express js routes handler that will automatically generate API routes for you based on the folder structure.
RouterHandler
options:app
- your express server instance.
routesPath
- the path to your routes folder - Use the path
library to define this.
basePath
- this changes your API routing. For example: By default your requests could look something like this:
http://localhost:3000/users
Adding a basePath
like /api
will change the routing to look like this:
http://localhost:3000/api/users
IMPORTANT: Adding a trailing slash to basePath
will affect your routing.
const path = require('path');
const express = require('express');
const RouterHandler = require('express-router-handler');
const app = express();
const PORT = 3000;
new RouterHandler({
app,
// IMPORTANT: Use the path library to define routesPath
routesPath: path.join(__dirname, 'routes'),
// basePath: '/api', // optional
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
import express, { Application } from 'express';
import RouterHandler from 'express-router-handler';
import path from 'path';
const app: Application = express();
const PORT = 3000;
new RouterHandler({
app,
// IMPORTANT: Use the path library to define routesPath
routesPath: path.join(__dirname, 'routes'),
// basePath: '/api', // optional
});
app.listen(PORT, () => {
console.log(`Server running on port ${PORT}`);
});
Your route file needs to export a function
/routes/users/:id/get.js
module.exports = (req, res) => {
const id = req.params.id;
res.send(`User id: ${id}`);
};
/routes/users/:id/get.js
import { Request, Response } from 'express';
module.exports = (req: Request, res: Response) => {
const id = req.params.id;
res.send(`User id: ${id}`);
};
ES6 JS currently has a few bugs related to imports/exports so I wouldn't recommend using it. So far I've tested in both CommonJS and TypeScript with the above examples and it has no issues.
FAQs
Handle express routes in a simpler way.
The npm package express-router-handler receives a total of 0 weekly downloads. As such, express-router-handler popularity was classified as not popular.
We found that express-router-handler 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
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.