app.use(express.json()) breaks Formidable
See original GitHub issueContext
- node version: 12.6.0
- module (formidable) version: canary
- environment (e.g. node, browser, native, OS): node
What are you trying to achieve or the steps to reproduce?
const express = require('express');
const app = express();
app.use(express.json()); // <-- breaks formidable
let formidable = require('formidable');
let router = express.Router();
router.route('/v1/user-form')
.post(function (req, res)
{
try
{
let form = new formidable.IncomingForm();
form.parse(req, function(err, fields, files)
{
console.log('form fields', fields);
});
}
catch(error)
{
console.log(error);
}
});
When I add app.use(express.json()); to my server.js file this line causes formidable to break / hang with no error. As soon as I comment out that line, formidable works as expected.
I know that app.use(express.json()) gives access to req.body but not sure why this is breaking formidable.
When I debug the formidable.js file I noticed that on(‘data’) is never called when express.json() is used.
// Start listening for data.
req
.on('error', (err) => {
this._error(err);
})
.on('aborted', () => {
this.emit('aborted');
this._error(new Error('Request aborted'));
})
.on('data', (buffer) => {
try {
this.write(buffer);
} catch (err) {
this._error(err);
}
})
.on('end', () => {
if (this.error) {
return;
}
if (this._parser) {
this._parser.end();
}
this._maybeEnd();
});
I googled a bunch of times to see if there was any similar issues but I could not find anyone that was was having similar issue.
Thanks in advance for any help or suggestions.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Express.js POST Requests not working after installing express ...
Okay I found a way to send requests through the multipart/form data and the application/json without breaking any thing.
Read more >5.x API - Express.js
Returns middleware that only parses JSON and only looks at requests where the Content-Type header matches ... Routing HTTP requests; see for example,...
Read more >What Does `app.use(express.json())` Do in Express?
express.json() is a built in middleware function in Express starting from v4.16.0. It parses incoming JSON requests and puts the parsed data in ......
Read more >body-parser - npm
Express /Connect top-level generic. This example demonstrates adding a generic JSON and URL-encoded parser as a top-level middleware, which will ...
Read more >bodyParser is deprecated express 4 - node.js
body-parser deprecated bodyParser: use individual json/urlencoded ... app.use(express.urlencoded({extended: true})); app.use(express.json()) // To parse the ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
We are handling json by deafult too. Disable the json plugin (see “enabledPlugins” docs) and probably the urlencodeded one, and then you should be able to use express.json() without problems.
for us: @GrosSacASac we probably should export a proper middleware which would be recommended. i always thought for that.
Use this package: express-formidable-v2 Check this []https://github.com/Abderrahman-byte/express-formidable-v2 out, It is a fork of “express-formidable” package
Now you have req.fields and req.body coexisting