'req.on is not getting trigger while using type application/json
req.on("data", (chunk) => {
console.log("daataa second",body)
body += chunk.toString();
});
When i am posting the data from the postman as the type then it successfully processing the data but when i am passing the data in json format then it is not triggering this method.
If i use json middleware, then none of the data or end event on request object is fired but I removed the json parser from your code, and then the events started firing
Solution 1:[1]
JSON parser middleware reads the entire request stream containing a JSON payload, parses it and creates a JavaScript object for you. For example in Express, express.json returns middleware that reads and saves JSON payloads as the req.body object if the request contains JSON data
JSON middleware needs to read the entire request stream in order to parse its content using JSON.parse(string), and so will not call next to invoke further steps in request routing before the stream has been read and parsed. Hence listeners added later in the route to monitor data and/or end events will not fire because the data has already been read, and the end event has already fired.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | traktor |
