Increasing body limit size in apollo-server-express

若如初见. 提交于 2020-01-24 11:27:48
问题 I am trying to upload files to a webservice using the Upload scalar in apollo-server-express. I can upload small files(10s of kbs) to the webservice but am having trouble getting larger files to send. I did some searching and found that I can change the body size limit using the body-parser package, along with the bodyParserConfig option set in middleware. I've tried implementing this, as well as implementing it in the express app itself, however neither seem to be working. bodyParserConfig

Express body-parser handling checkbox arrays on forms

こ雲淡風輕ζ 提交于 2020-01-21 12:19:10
问题 I have an HTML form with an array of checkboxes (using [] naming). I need to be able to process this with express . I'm using body-parser . The problem is that unchecked checkboxes don't submit a value, and at the same time, body-parser seems to remove "holes" in arrays by simply packing the values into an array in order of indices, but ignoring the indices themselves. (Update: Actually it looks like qs is the culprit). Consider this full example, which displays a form and responds with a

Parse Error response in Express NodeJS app

泄露秘密 提交于 2020-01-06 08:45:08
问题 I am trying to send a specific error message to my front end. Scenario 1 app.use(function(err, req, res, next){ console.log(err); }); logs: [String: 'Error: Request returned error code: 422 and body: {"status":422,"title":"Missing or incorrect required fields","type":"","errors":{"variant":"This product has options, variant ID is required"}}'] Scenario 2 app.use(function(err, req, res, next){ res.status(422).send('TEST TEST TEST'); });

How to access raw body of a post request in Express.js?

你离开我真会死。 提交于 2020-01-06 07:16:31
问题 I send this request with postman. And I console.log(req.body) returns an array like this: { '{"urls":["': 'foo', paramTwo: 'bar"]}' } How can I get the whole body as a simple string like this? {"urls":[""]} 回答1: In app.js : Replace: app.use(express.json()); With: var rawBodySaver = function (req, res, buf, encoding) { if (buf && buf.length) { req.rawBody = buf.toString(encoding || 'utf8'); } } app.use(bodyParser.json({

Express' render/redirect does not work if the call isn't coming from a submit method in a form

自作多情 提交于 2019-12-30 10:08:12
问题 Task Perform a POST request from a JS method, so that variable values can be sent as parameters. Environment NodeJS Express BodyParser ejs My first attempt Frontend: <html> <head> <script src=''></script> <script type="text/javascript"> function postAnswer() { $.post('vote', { message: "hello!"}, function(returnedData) { console.log("Post returned data: " + returnedData); }); } </script> </head> <body> <button id='send' onClick=

What does 'extended' mean in express 4.0?

穿精又带淫゛_ 提交于 2019-12-28 02:26:04
问题 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. 回答1: 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. 回答2: When extended property is set to true ,

Express, Multer, BodyParser req.body empty array

六月ゝ 毕业季﹏ 提交于 2019-12-25 07:38:54
问题 Sorry for such a noob question, but I have a form upload images and add some text to the DB, the images are uploading fine, but the req.body object is always an empty array. HTML <form class='new-project' action='/projects' method='POST' enctype="multipart/form-data"> <input type="text" name="title" placeholder="Project Title"> <br> <textarea name="description" rows="8" cols="40" placeholder="Project description"></textarea> <br> <label for='file'>Select your image:</label> <input type='file'

I can't get values from req.body node.js

*爱你&永不变心* 提交于 2019-12-25 03:36:25
问题 I need help with node.js: I have my req.body populated like this { '{ "email":"", "password":"12345" }' : '' } but I can't get values and req.body.password are undefined My code is: user.js exports.loginByEmail= function(req, res) { console.log('POST'); console.log(req.body);//show values console.log(;//undefined console.log(req.body.password);//undefined User.find({,password:req.body.password}).toArray(function(err, userLoged

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 =