nodejs route的简单使用

demo

var  express=require('express');
var app=express();
var  routeUser=express.Router();
var  routeTeacher=express.Router();

routeUser.get('/use1.html',function(req,res)  {
    res.send('user1:张三')
});
routeUser.get('/use2.html',function(req,res) {
    res.send('user2:李四')

});
app.use('/use',routeUser);

routeTeacher.get('/teacher1.html',function(req,res)  {
    res.send('teacher1:jack')
});


routeTeacher.get('/teacher2.html',function(req,res)  {
    res.send('teacher2:mike')
});
app.use('/teacher',routeTeacher);



app.listen(8080);

效果:

 

posted @ 2017-11-12 17:05  1点  阅读(2612)  评论(0编辑  收藏  举报