首页 > 移动平台 > 详细

node——app.get与app.use的区别

时间:2019-06-14 17:15:11      阅读:315      评论:0      收藏:0      [点我收藏+]
 

app.get和app.post

1.请求的方法必须是get/post
2.请求的路径的pathname必须等于(====)路径

app.use

1.在进行路由匹配的时候不限定方法,什么请求方法都可以
2.请求路径中的第一部分只要与/index相等即可,并不要求路径完全匹配

var express=require(‘express‘);
var app=express();

//通过中间件监听指定路由请求

app.get(‘/‘,function(req,res){
    res.send(‘Index‘);
});
app.get(‘/submit‘,function(req,res){
    res.send(‘submit‘);
});
app.get(‘/item‘,function(req,res){
    res.send(‘item‘);
});
app.post(‘/add‘,function(req,res){
    res.send(‘add‘);
});

app.use(‘/index‘,function(req,res){
    res.send(‘hhh,|> v <|‘);
})

app.listen(9092,function(){
    console.log(‘http://localhost:9092‘);
})

app.get

技术分享图片

技术分享图片

 

 

app.use

技术分享图片

 

 技术分享图片

 

可按实际需要选择使用

node——app.get与app.use的区别

原文:https://www.cnblogs.com/ellen-mylife/p/11024207.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!