Javascript 这个node.js项目中我的localhost:5000/users url有什么问题?

Javascript 这个node.js项目中我的localhost:5000/users url有什么问题?,javascript,node.js,express,url,Javascript,Node.js,Express,Url,我正在使用node.js构建一个REST CRUD,并且为了检查我的url是否正常工作,我试图在访问url“localhost:5000/users”时获得一条“Hello1”消息,但是当我访问它时,我得到的只是无法获得/users。我真的不知道我的代码出了什么问题,因为我完全按照教程所说的去做。有人知道发生了什么事吗 users.js文件: import express from 'express'; const router = express.Router(); router.get

我正在使用node.js构建一个REST CRUD,并且为了检查我的url是否正常工作,我试图在访问url“localhost:5000/users”时获得一条“Hello1”消息,但是当我访问它时,我得到的只是无法获得/users。我真的不知道我的代码出了什么问题,因为我完全按照教程所说的去做。有人知道发生了什么事吗

users.js文件:

import express from 'express';

const router = express.Router();


router.get('/' , (req,res) => {
    res.send("Hello1");
});

export default router;
////////////////////////////////////// index.js文件

import express from 'express';
import bodyParser from 'body-parser';
import usersRoutes from './routes/users.js';


const app = express();
const PORT = 5000;

app.use(bodyParser.json());


app.get('/', (req,res) => {
    res.send("hello");
})

app.get('/users', usersRoutes);

app.listen(PORT, () => console.log("Server running on localhost:"+PORT));
而不是:

app.get('/users', usersRoutes);
你应使用:

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