Load routers from specific folders for Express 4.x
npm i express-load-routers
const path = require('path');
const express = require('express');
const loadRouters = require('express-load-routers');
const app = express();
app.use(loadRouters('./routes'));
loadRouters(directory, options);
option | type | default | decription |
---|---|---|---|
exclude | Array | ['_*'] | This array contain match patterns that will excludes. |
ex) routes/sample.js -> http://localhost/sample/
module.exports = router = require('express').Router();
router.get('/', (req, res, next)=>{
res.send('OK');
});
ex) routes/camel/index.js -> http://localhost/camel/
ex) routes/one/two.js -> http://localhost/one/two/three/
module.exports = router = require('express').Router();
router.get('/three', (req, res, next)=>{
res.send('OK');
});
MIT License.