app.use(bodyParser.json());和bodyParser.urlencoded({extended:true})方法未解决

时间:2016-02-05 21:26:06

标签: node.js

我正在使用webstorm并且我已安装了body-parser模块,但bodyParser.jsonbodyParser.urlencoded仍然提供了一个未解决的方法错误。

var express = require('express');
var connect = require('connect');
var logger  = require('morgan');
var bodyParser = require('body-parser');
var app = express();
port = process.env.PORT || 8080;

app.use(logger('dev'));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

require('./routes.js')(app);

app.listen(port);

console.log('The App runs on port ' + port);

路线

   var requests = require('config/requests');
 var request = require('request');


 module.exports = function(app) {



app.get('/', function(req, res) {

    res.end("Node-Android-Chat-Project"); 
});


app.post('/login',function(req,res){
    var name = req.body.name;
        var mobno = req.body.mobno;
        var reg_id = req.body.reg_id;

    requests.login(name,mobno,reg_id,function (found) {
        console.log(found);
        res.json(found);
});     
});

app.post('/send',function(req,res){
    var fromu = req.body.from;
    var fromn = req.body.fromn;
        var to = req.body.to;
        var msg = req.body.msg;


    requests.send(fromn,fromu,to,msg,function (found) {
        console.log(found);
        res.json(found);
});     
});

app.post('/getuser',function(req,res){
    var mobno = req.body.mobno;

    requests.getuser(mobno,function (found) {
        console.log(found);
        res.json(found);
});     
});

app.post('/logout',function(req,res){
    var mobno = req.body.mobno;


    requests.removeuser(mobno,function (found) {
        console.log(found);
        res.json(found);
});     
});

};

1 个答案:

答案 0 :(得分:0)

尝试再次安装body-parser模块。

使用npm install body-parser --save