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')
}) |
|