node.jsexpress

when I search `localhost:3000/users`, it's said not found. What's wrong?


enter image description here enter image description here

I'm using Express framework, app.use() in app.js and router.get() in users.js. When I search localhost:3000/users/u it works fine, but when I search localhost:3000/users, it's a 404 error. What's wrong?


Solution

  • This is because /users call redirects to your users.js module and you don't handle / in it. To fix this, simply add the route:

    // users.js
    
    router.get('/', function (req, res) {
      console.log('It works');
      // ...
    });