码迷,mamicode.com
首页 > 数据库 > 详细

Node+MongoDB数据接口的开发

时间:2018-04-26 14:08:40      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:urlencode   UNC   http请求   install   var   src   detail   请求   net   

1.接收前台数据返回数据

    1)npm    install    body-parser(HTTP请求体解析中间件)

    2)   app.js引入模块body-parser

        var    bodyParser    =    require(‘body-parser‘);

        app.use(bodyParser,urlencoded({extended:false}));

        app.use(bosyParser.json());

        app.post(‘/123‘,function(req,res){

            if(!req.body){

                return    res.sendStatus(400)

            }else{

                console.log(req.body);

                res.send(返回前台的数据);

            }

        })

        技术分享图片

        技术分享图片

        技术分享图片

技术分享图片

    *************get请求接口点击这里点击打开链接**************

        

Node+MongoDB数据接口的开发

标签:urlencode   UNC   http请求   install   var   src   detail   请求   net   

原文地址:https://www.cnblogs.com/diegomock/p/8951752.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!