body-parser

fetch() POST request to Express.js generates empty body {}

六眼飞鱼酱① 提交于 2019-12-24 03:36:19
问题 Goal: send some defined string data from HTML in a fetch() function e.g. "MY DATA" My code: HTML <!DOCTYPE html> <html> <body> <script type="text/javascript"> function fetcher() { fetch('/compute', { method: "POST", body: "MY DATA", headers: { "Content-Type": "application/json" } } ) .then(function(response) { return response.json(); }) .then(function(myJson) { console.log(myJson); }); } </script> </body> </html> Server.js var express = require("express"); var app = express(); var compute =

Proper way to use connect-multiparty with express.js?

两盒软妹~` 提交于 2019-12-24 00:44:53
问题 I am trying to upload files to my server and extract them from the post request using the connect-multiparty middleware. However, when I receive the request on the server, the req.files and req.body objects are empty (not null, but node-inspector shows that they are Object s with nothing in them. Here is the code that I'm working with: server.js: var express = require( "express" ); var app = express(); var server = require( "http" ).Server( app ); var fs = require( "fs" ); var multipart =

req.body undefined on server side

社会主义新天地 提交于 2019-12-23 09:26:30
问题 I am working on app which uses node, express, mysql on server side. i have written serveral APIs on server.js file and when i am trying to access those using Postman then req.body is always undefined. this is my server.js configuration. var express = require('express'); var mysql = require('mysql'); var cors = require('cors'); var bodyParser = require('body-parser'); var wrench = require("wrench"); var fs = require('fs'); var path = require("path"); var mkdirp = require('mkdirp'); var walk =

Express body-parser req.body with formdata is empty object

一个人想着一个人 提交于 2019-12-22 08:55:08
问题 Somehow my req.body is always empty, maybe you have an idea: here is my server code: const Express = require('express'); const bodyParser = require('body-parser'); const app = new Express(); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); app.post('/save', (req, res) => { console.log(req.body) // => {} res.send(req.body); }); const env = process.env.NODE_ENV || 'production'; app.listen(3000, err => { if (err) { return console.error(err); } console.info(`Server

Express body-parser req.body with formdata is empty object

狂风中的少年 提交于 2019-12-22 08:54:23
问题 Somehow my req.body is always empty, maybe you have an idea: here is my server code: const Express = require('express'); const bodyParser = require('body-parser'); const app = new Express(); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); app.post('/save', (req, res) => { console.log(req.body) // => {} res.send(req.body); }); const env = process.env.NODE_ENV || 'production'; app.listen(3000, err => { if (err) { return console.error(err); } console.info(`Server

Current URL string parser is deprecated [duplicate]

徘徊边缘 提交于 2019-12-21 07:03:02
问题 This question already has answers here : Avoid “current URL string parser is deprecated” warning by setting useNewUrlParser to true (18 answers) Closed last year . when I run the code by "node app.js" command this error is showing (node:2509) DeprecationWarning: current URL string parser is deprecated, and will be removed in a future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect. 回答1: You need to pass { useNewUrlParser: true } option to mongoose

body is empty when parsing DELETE request with express and body-parser

梦想的初衷 提交于 2019-12-20 01:06:28
问题 I'm using expressjs and the body-parser middleware. This is how I initiate it: app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); From the client I'm sending a DELETE request and when I try to pick it up from the server side I get an empty object: app.delete('/', function(req, res) { console.log(util.inspect(req.body)); //outputs {} //some more code }); however when I send it with a POST I get what I need: app.post('/delete', function(req, res) { console.log(util

Can't get POST data using NodeJS/ExpressJS and Postman

▼魔方 西西 提交于 2019-12-18 19:31:31
问题 This is the code of my server : var express = require('express'); var bodyParser = require("body-parser"); var app = express(); app.use(bodyParser.json()); app.post("/", function(req, res) { res.send(req.body); }); app.listen(3000, function () { console.log('Example app listening on port 3000!'); }); From Postman, I launch a POST request to http://localhost:3000/ and in Body/form-data I have a key "foo" and value "bar". However I keep getting an empty object in the response. The req.body

Node js Converting pdf Buffer back to pdf

守給你的承諾、 提交于 2019-12-18 16:57:31
问题 I have created a pdf with the browser in Javascript and sent it via post to the server using this code: var blob = pdf.output('blob') var xhr = new XMLHttpRequest(); xhr.open('post','/upload', true); xhr.setRequestHeader("Content-Type", "application/pdf"); xhr.send(blob); I would like to save as pdf on the server running Node with express. I have come up with the following code using express and body-parser package: const bodyParser = require('body-parser'); app.use(bodyParser.urlencoded({

How can I use body-parser with LoopBack?

别说谁变了你拦得住时间么 提交于 2019-12-18 11:07:31
问题 I see that LoopBack has the Express 3.x middleware built-in. Indeed, body-parser is in loopback/node_modules . But I cannot figure out how to use it as middleware. I have never worked with Express 3.x, so maybe it's just that. require does not work, obviously, unless I install body-parser as a dependency in my project. What should I do in server.js to use body-parser so that web forms are parsed into req.params ? That's what it does, right? 回答1: After hours of frustration, I just added it to