在搜索了,如何将监听多个节点,如何访问服务器不同文件等等之后 。发现搜索错了。
我只是想将文件挂载在不同路由上。
实例
index.js
const express = require(‘express‘) const app = express() const indexRouter = require(‘./routes/index‘) const userRouter = require(‘./routes/users‘) app.use(‘/‘, indexRouter) app.use(‘/users‘, userRouter) app.listen(3000)
routes/index.js
const express = require(‘express‘) const router = express.Router() router.get(‘/‘, function (req, res) { res.send(‘hello, express‘) }) module.exports = router
routes/users.js
const express = require(‘express‘) const router = express.Router() router.get(‘/:name‘, function (req, res) { res.send(‘hello, ‘ + req.params.name) }) module.exports = router
参考自:https://github.com/nswbmw/N-blog/blob/master/book/3.2%20%E8%B7%AF%E7%94%B1.md