黑马程序员技术交流社区
标题:
1
[打印本页]
作者:
黄心灵
时间:
2019-6-27 17:49
标题:
1
const express = require('express')
const app = express()
app.get('/', (req, res) => {
res.sendFile('./views/home.html', { root: __dirname })
})
app.get('/movie', (req, res) => {
res.sendFile('./views/movie.html', { root: __dirname })
})
app.get('/about', (req, res) => {
res.sendFile('./views/about.html', { root: __dirname })
})
app.listen(3000, () => {
console.log('server running at http://127.0.0.1:3000')
})
1. const express = require('express')
2. const router = express.Router()
router.get('/', (req, res) => {
res.sendFile('./views/home.html', { root: __dirname })
})
router.get('/movie', (req, res) => {
res.sendFile('./views/movie.html', { root: __dirname })
})
router.get('/about', (req, res) => {
res.sendFile('./views/about.html', { root: __dirname })
})
module.exports = router
const express = require('express')
const app = express()
// 将路由对象的js文件 导入
const router = require(将路由对象的js文件)
app.use(router) //注册路由中间件
app.listen(3000, () => {
console.log('server running at http://127.0.0.1:3000')
})
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2