node.js - app.use(bodyParser.json()); and bodyParser.urlencoded({ extended: true }) method unresolved -
i using webstorm , have installed body-parser module bodyparser.json
, bodyparser.urlencoded
still gives unresolved method error.
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);
routes
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 = 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); }); });
};
trying installing body-parser
module again.
use npm install body-parser --save
Comments
Post a Comment