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);

效果:

nodejs  route的简单使用_IT

 

越努力越幸运