I'm trying to figure out why the routing doesn't work if I use expressjs
, I have this code:
const express = require('express');
const app = express();
const router = express.Router();
app.get('/foo', function (req, res) {
res.send('Hello World.')
});
the code above works well, but if I replace the route with this:
router.get('/foo', function(req, res, next) {
res.send('This is api.')
});
I get:
Cannot GET /foo when using express.Router()