Answer for Question 1:
To limit the HTTP request size and upload file size we need to set the body-parser
limit.
app.use(bodyParser.urlencoded({limit: '50mb',extended: true}));
app.use(bodyParser.json({limit: '50mb'}));
bodyParser.urlencoded
The files from the front end comes as urlencoded bodies.
Returns middleware that only parses urlencoded bodies. This parser accepts only UTF-8 encoding of the body and supports automatic inflation of gzip and deflate encodings.
A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body). This object will contain key-value pairs, where the value can be a string or array (when extended is false), or any type (when extended is true).
bodyParser.json
Returns middleware that only parses json. This parser accepts any Unicode encoding of the body and supports automatic inflation of gzip and deflate encodings.
A new body object containing the parsed data is populated on the request object after the middleware (i.e. req.body).
Note:
By default the input limit for body parser is 100kb
Answer for Question 2:
To change the default upload directory we can use the following.
app.set('uploadDir', './files'); // Sets the upload Directory to files folder in your project.
Other Implementation
While including the bodyParser into the app we can mention the upload directory.
app.use(express.bodyParser({uploadDir:'./files', keepExtensions: true}));
Reference:
Issues: https://github.com/expressjs/express/issues/1684
Hope this helps!