Nodejs uses app. use (express. bodyParser (); Travel exception ---- solution, nodejsapp. use

Source: Internet
Author: User

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);})

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.