Comments (8)
Ok, I see. you created a circular dependency. You just need to remove the two app.use()
statements to make your server look like this:
var express = require("express")
var bp = require("body-parser")
var app = express()
var bpurle= bp.urlencoded({ extended: false })
var bpjson= bp.json()
app.post("/urle", bpurle, function(req, res) {
if (req.body === undefined) {return(console.log("There aren't any data"))}
console.log("Received data via URL-Encode:\n" + req.body)
})
app.post("/json", bpjson, function(req, res) {
if (req.body === undefined) {return(console.log("There aren't any data"))}
console.log("Received data via JSON:\n" + JSON.stringify(req.body,null,2))
})
app.listen(4000)
from body-parser.
Hi! So, really, there are two different questions here. Regarding the second error from JSON.parse, the reason you get the error is because the '
is not valid JSON; you can only use double quotes. This is just how the JSON format is defined, and nothing from this module.
For the first error, I''m not sure what is going on. What is the version of Express you are using?
from body-parser.
Thanks.
Last stable: 4.11
Edit: Sorry, maybe it's important. And Node v0.11.14
from body-parser.
Well...if I correct my JSON mistake and I do...
curl -X POST http://127.0.0.1:4000/json -d '{"data1":"value1","data2":"1234"}' -H "Content-Type:application/json"
(namely, inverting simple and double quotes), I get the same error than with url-encode format:
RangeError: Maximum call stack size exceeded
at global.setImmediate (node.js:198:29)
at next (/home/q2dg/node_modules/express/lib/router/index.js:188:7)
at Layer.handle [as handle_request] (/home/q2dg/node_modules/express/lib/router/layer.js:84:5)
at trim_prefix (/home/q2dg/node_modules/express/lib/router/index.js:302:13)
at /home/q2dg/node_modules/express/lib/router/index.js:270:7
at Function.proto.process_params (/home/q2dg/node_modules/express/lib/router/index.js:321:12)
at next (/home/q2dg/node_modules/express/lib/router/index.js:261:10)
at expressInit (/home/q2dg/node_modules/express/lib/middleware/init.js:23:5)
at Layer.handle [as handle_request] (/home/q2dg/node_modules/express/lib/router/layer.js:82:5)
at trim_prefix (/home/q2dg/node_modules/express/lib/router/index.js:302:13)
I've also noticed if I repeat curl command, the error message is similar but line numbers is not (I don't know if it is relevant):
RangeError: Maximum call stack size exceeded
at trim_prefix (/home/q2dg/node_modules/express/lib/router/index.js:297:5)
at /home/q2dg/node_modules/express/lib/router/index.js:270:7
at Function.proto.process_params (/home/q2dg/node_modules/express/lib/router/index.js:321:12)
at next (/home/q2dg/node_modules/express/lib/router/index.js:261:10)
at Layer.handle_error (/home/q2dg/node_modules/express/lib/router/layer.js:54:12)
at trim_prefix (/home/q2dg/node_modules/express/lib/router/index.js:300:13)
at /home/q2dg/node_modules/express/lib/router/index.js:270:7
at Function.proto.process_params (/home/q2dg/node_modules/express/lib/router/index.js:321:12)
at next (/home/q2dg/node_modules/express/lib/router/index.js:261:10)
at Layer.handle [as handle_request] (/home/q2dg/node_modules/express/lib/router/layer.js:84:5)
Thanks a lot for your patience
from body-parser.
And you are sure that the code at the top is the only code for the entire server you are getting the RangeError
on?
from body-parser.
Yes, totally
from body-parser.
Ooooh, so sorry!!
I though all Express middleware had to be inside app.use() to work (like serve-static, serve-index and so on) but it's not the case. Now I understand why: because i'm using it inside routing.
Thanks a lot again!!
from body-parser.
It's no problem, I didn't even notice it at first, which is why I wanted to confirm that was your server's code before I ran it myself to figure it out :)
from body-parser.
Related Issues (20)
- bodyParser is deprecated, error HOT 1
- bodyparser.json() shown as deprecated? (question) HOT 7
- pass options to qs thru urlencoded? HOT 4
- Cannot catch SyntaxError when user provides invalid JSON in body and content-type: application/json HOT 3
- Support for content-encoding: deflate raw HOT 7
- req.body could not be accessed when send as form data, but works fine with JSON HOT 3
- Pass custom parameters to `qs` HOT 3
- Update iconv-lite to latest 0.6.3 HOT 7
- support for ndjson
- Regular Expression Denial of Service (ReDoS) in [email protected] HOT 3
- Update `debug` dependency (memory leak leading to vulnerability) HOT 1
- api calls made with invalid json HOT 5
- Add support for removing body parser limit HOT 8
- BadRequestError: request size did not match content length HOT 7
- How to handle content-type mismatch? HOT 1
- CVE-2017-20165 - debug HOT 2
- Issue HOT 1
- Debug package version in body parser showing security vulnerability HOT 10
- fails silently if the json has extra whitespace HOT 2
- json middleware does not work on content types with a `+` HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from body-parser.