I can't send 1 mb base64image json data with nodejs even though I have body-parser installed.
This is my app.js
const bodyParser = require('body-parser');
const express = require('express');
const cors = require('cors');
const path = require('path');
const authRoutes = require('./src/routes/auth');
const guestRoutes = require('./src/routes/guest');
const memberRoutes = require('./src/routes/member');
const isAuth = require('./src/middleware/jwtMiddleware');
const app = express();
const PORT = process.env.PORT || 3001;
app.use(cors({
origin: 'http://localhost:5173',
credentials: true
}));
// Parse incoming request bodies in a middleware before your handlers, available under the req.body property
app.use(bodyParser.json({ limit: '50mb' }));
app.use(bodyParser.urlencoded({ limit: '50mb', extended: true }));
// Serve static files from the 'public' directory
app.use('/public', express.static(path.join(__dirname, 'public')));
app.use('/auth', authRoutes);
app.use('/guest', guestRoutes);
app.use('/member', isAuth, memberRoutes);
app.use('/test', function (req, res) {
return res.json(req.body);
});
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
This is my error log
Node.js v20.9.0
BadRequestError: request aborted
at IncomingMessage.onAborted (/home/iogmwebs/nodevenv/ykomara-backend.iogm.website/20/lib/node_modules/raw-body/index.js:245:10)
at IncomingMessage.emit (node:events:514:28)
at IncomingMessage._destroy (node:_http_incoming:224:10)
at _destroy (node:internal/streams/destroy:109:10)
at IncomingMessage.destroy (node:internal/streams/destroy:71:5)
at abortIncoming (node:_http_server:793:9)
at socketOnClose (node:_http_server:787:3)
at Socket.emit (node:events:526:35)
at Pipe.<anonymous> (node:net:337:12)
So this happens when in production cpanel nodejs. Previously I ran npm install and got the error:
Error: Cannot find module 'body-parser'
but I manually opened the cpanel terminal and installed it personally and it worked :
npm i body-parser
up to date, audited 242 packages in 2s
35 packages are looking for funding
run `npm funds` for details
found 0 vulnerabilities.
I hope those of you who are experienced can answer this. Thank You