I am building a web application using the Node JS Express JS framework. Now, I am trying to add a prefix to all the routes of my application. But it is not working.
This is how I did it.
let express = require('express');
let app = express();
const apiRouter = express.Router()
apiRouter.use('/api', () => {
app.get('/auth', (req, res) => {
res.send("Auth route")
})
return app;
})
When I go to the '/api/auth' in the browser, I am not getting the expected response. I am getting the following error.
Cannot GET /api/auth
What is wrong with my code and how can I fix it?