0

I cant seem to use the same endpoint in different route files.

index.js:

var users = require('./routes/users.js');
var orders = require('./routes/orders.js');


app.use('/users', users);
app.use('/orders', orders);

routes/users.js:

baseDep.router.get('/', function (req, res) {
    res.json("This is the users route");
});

routes/orders.js

baseDep.router.get('/', function (req, res) {
    res.json("This is the orders route");
});

localhost:3000/orders --> This is the users route

localhost:3000/users --> This is the users route

The second one works as expected.

The first one seems to using the endpoint in the users route file.

Can someone help figure out what I need to do?

mendez7
  • 195
  • 1
  • 3
  • 14

1 Answers1

0

If you have a look at the documentation for express app.use() method, it tells you that you need to use next() function in the middleware so that is can move on: https://expressjs.com/en/4x/api.html#app.use

For example:

baseDep.router.get('/', function (req, res, next) {
    res.json("This is the users route");
    next();
});