Git Product home page Git Product logo

Comments (8)

dougwilson avatar dougwilson commented on May 2, 2024 3

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.

dougwilson avatar dougwilson commented on May 2, 2024

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.

q2dg avatar q2dg commented on May 2, 2024

Thanks.
Last stable: 4.11

Edit: Sorry, maybe it's important. And Node v0.11.14

from body-parser.

q2dg avatar q2dg commented on May 2, 2024

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.

dougwilson avatar dougwilson commented on May 2, 2024

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.

q2dg avatar q2dg commented on May 2, 2024

Yes, totally

from body-parser.

q2dg avatar q2dg commented on May 2, 2024

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.

dougwilson avatar dougwilson commented on May 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.