demo37.js
const express = require('express');const app = express();
const home = require('./home');
const admin = require('./admin');app.use('/home', home);
app.use('/admin', admin);app.listen(3000);
console.log('服务器启动成功');
home.js
const express = require('express');
const home = express.Router();home.get('/index', (req, res) => {res.send('欢迎来到博客首页')
});
module.exports = home;
admin.js
const express = require('express');
const admin = express.Router();admin.get('/amdin', (req, res) => {res.send('欢迎来到博客管理')
});
module.exports = admin;
运行结果