index.js
const express = require('express')
const app = express()
// const router=express.Router();
app.get('/', function (req, res) {
res.send('Hello World')
})
// 使用路由設定檔
app.use('/news', require(__dirname+'/news'));
// 設定靜態路由
app.use(express.static('public'));
app.listen(3000);
news.js
const express = require('express');
const router = express.Router();
router.get('/', (req, res)=>{
res.send('1');
})
router.get('/kk/', (req, res)=>{
res.send('kk');
})
// 匯出模組
module.exports = router;