Nodejs uses app. use (express. bodyParser (); Travel exception ---- solution, nodejsapp. use
Exception Code:
\Workspaces\WebStormProject\imooc-project\imooc>node app.jsError: Most middleware (like bodyParser) is no longer bundled with Express and must be installed separately. Please see https://github.com/senchalabs/connect#middleware. at Function.Object.defineProperty.get (L:\Workspaces\WebStormProject\imooc-project\imooc\node_modules\express\lib\express.js:89:13) at Object.<anonymous> (L:\Workspaces\WebStormProject\imooc-project\imooc\app.js:12:17) at Module._compile (module.js:456:26) at Object.Module._extensions..js (module.js:474:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:312:12) at Function.Module.runMain (module.js:497:10) at startup (node.js:119:16) at node.js:902:3
Current express version: 3.5.3
According to the error, we can know that bodyparser is not bound with Express. It means that the current express does not contain body-parser. Run the following command: npm install body-parser
Solution:
var app = require('express')();var bodyParser = require('body-parser');var multer = require('multer'); app.use(bodyParser.json()); // for parsing application/jsonapp.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencodedapp.use(multer()); // for parsing multipart/form-dataapp.post('/', function (req, res) { console.log(req.body); res.json(req.body);})