I have an app with following code for routing:
var router = express.Router();
router.post(\'/routepath\', function(req, res) {});
Now I have
Here's a simple example:
// myroutes.js
var router = require('express').Router();
router.get('/', function(req, res) {
res.send('Hello from the custom router!');
});
module.exports = router;
// main.js
var app = require('express')();
app.use('/routepath', require('./myroutes'));
app.get('/', function(req, res) {
res.send('Hello from the root path!');
});
Here, app.use()
is mounting the Router
instance at /routepath
, so that any routes added to the Router
instance will be relative to /routepath
.