body-parser

How to upload file using multer or body-parser

雨燕双飞 提交于 2019-11-28 07:13:30
问题 I am a NodeJS beginner, following along a book "Web Development with MongoDB and NodeJS". I am stuck at its chapter 6 with 'multer'. When I use multer for file uploads the server throws the following error: /Users/fk / Documents / imageuploader / node_modules / express / lib / application.js: 209 throw new TypeError('app.use() requires middleware functions'); ^ TypeError: app.use() requires middleware functions but when I replace it with bodyParser the server fires up but when I click the

body-parser - extended option (qs vs querystring)

南笙酒味 提交于 2019-11-27 13:15:10
In the current version of body-parser , the extended option when using bodyParser.urlencoded() is now required. In the README, it explains: The extended option allows to choose between parsing the URL-encoded data with the querystring library (when false) or the qs library (when true). [...] Defaults to true, but using the default has been deprecated. Please research into the difference between qs and querystring and choose the appropriate setting. I couldn't find any helpful or specific information on this. I only found a deprecated node-querystring . Should this option just always be true?

What does 'extended' mean in express 4.0?

雨燕双飞 提交于 2019-11-27 11:11:15
I'm using express and also body-parser in my app. app.use(bodyParser.urlencoded({ extended: false })); But, What does 'extended' mean in express 4.0? I found this extended - parse extended syntax with the qs module. However, I still can't understrand what it means. If extended is false , you can not post "nested object" person[name] = 'cw' // Nested Object = { person: { name: cw } } If extended is true , you can do whatever way that you like. When extended property is set to true , the URL-encoded data will be parsed with the qs library . On the contrary, when extended property is set to false

Node.js (with express & bodyParser): unable to obtain form-data from post request

狂风中的少年 提交于 2019-11-27 09:01:05
I can't seem to recover the form-data of a post request sent to my Node.js server. I've put below the server code and the post request (sent using postman in chrome): Post request POST /api/login HTTP/1.1 Host: localhost:8080 Cache-Control: no-cache ----WebKitFormBoundaryE19zNvXGzXaLvS5C Content-Disposition: form-data; name="userName" jem ----WebKitFormBoundaryE19zNvXGzXaLvS5C NodeJS server code var express = require('express'); // call express var app = express(); // define our app using express var bodyParser = require('body-parser'); app.use(bodyParser.urlencoded({ extended: true })); app

Express.js POST req.body empty

佐手、 提交于 2019-11-27 07:44:08
问题 So I have the following code in my server.js file that I'm running with node.js. I'm using express to handle HTTP requests. app.post('/api/destinations', function (req, res) { var new_destination = req.body; console.log(req.body); console.log(req.headers); db.Destination.create(new_destination, function(err, destination){ if (err){ res.send("Error: "+err); } res.json(destination); }); }); I'm running the following in Terminal: curl -XPOST -H "Content-Type: application/json" -d '{"location":

body-parser - extended option (qs vs querystring)

我只是一个虾纸丫 提交于 2019-11-26 16:08:07
问题 In the current version of body-parser, the extended option when using bodyParser.urlencoded() is now required. In the README, it explains: The extended option allows to choose between parsing the URL-encoded data with the querystring library (when false) or the qs library (when true). [...] Defaults to true, but using the default has been deprecated. Please research into the difference between qs and querystring and choose the appropriate setting. I couldn't find any helpful or specific

Node.js (with express & bodyParser): unable to obtain form-data from post request

£可爱£侵袭症+ 提交于 2019-11-26 09:49:44
问题 I can\'t seem to recover the form-data of a post request sent to my Node.js server. I\'ve put below the server code and the post request (sent using postman in chrome): Post request POST /api/login HTTP/1.1 Host: localhost:8080 Cache-Control: no-cache ----WebKitFormBoundaryE19zNvXGzXaLvS5C Content-Disposition: form-data; name=\"userName\" jem ----WebKitFormBoundaryE19zNvXGzXaLvS5C NodeJS server code var express = require(\'express\'); // call express var app = express(); // define our app

What does body-parser do with express?

允我心安 提交于 2019-11-26 02:36:27
I don't understand why we need body-parser in an Express application, as we can get data without using body-parser . And what does it do actually and how? Malatesh Patil To handle HTTP POST request in Express.js version 4 and above, you need to install middleware module called body-parser . body-parser extract the entire body portion of an incoming request stream and exposes it on req.body . The middleware was a part of Express.js earlier but now you have to install it separately. This body-parser module parses the JSON, buffer, string and URL encoded data submitted using HTTP POST request.