Problem: When the front-end axios uploads too much data, the back-end of node.js (express) reports an error or cancels the status.
The front-end post request body is very large, and the default post of node.js (express) backend is 2MB/1MB, so the size limit of the request body needs to be set.
app.use(express.json({
limit: '50mb'}));
app.use(express.urlencoded({
limit: '50mb',
extended: true,
}));
After setting up, another problem occurred, and the specific situation was not reported. Looking at the picture, the size of the MYSQL problem is known.
Error: read ECONNRESET
at TCP.onStreamRead (internal/stream_base_commons.js:209:20)
--------------------
at Protocol._enqueue (E:\Desktop\nodeProject\baker-mood\node_modules\mysql\lib\protocol\Protocol.js:144:48)
at PoolConnection.query (E:\Desktop\nodeProject\baker-mood\node_modules\mysql\lib\Connection.js:198:25)
at E:\Desktop\nodeProject\baker-mood\router\methods\MoodMethodes.js:23:25
at Handshake.onConnect (E:\Desktop\nodeProject\baker-mood\node_modules\mysql\lib\Pool.js:64:7)
at Handshake.<anonymous> (E:\Desktop\nodeProject\baker-mood\node_modules\mysql\lib\Connection.js:526:10)
at Handshake._callback (E:\Desktop\nodeProject\baker-mood\node_modules\mysql\lib\Connection.js:488:16)
at Handshake.Sequence.end (E:\Desktop\nodeProject\baker-mood\node_modules\mysql\lib\protocol\sequences\Sequence.js:83:24)
at Handshake.Sequence.OkPacket (E:\Desktop\nodeProject\baker-mood\node_modules\mysql\lib\protocol\sequences\Sequence.js:92:8)
at Protocol._parsePacket (E:\Desktop\nodeProject\baker-mood\node_modules\mysql\lib\protocol\Protocol.js:291:23)
at Parser._parsePacket (E:\Desktop\nodeProject\baker-mood\node_modules\mysql\lib\protocol\Parser.js:433:10) {
errno: -4077,
code: 'ECONNRESET',
syscall: 'read',
fatal: true
}
Error: read ECONNRESET
After various tortures and investigations, it turned out that the database MYSQL also has a parameter for uploading the limit size, which caused the upload of too large data to fail and report an error. Specifically, configure the upload limit size in the .ini file.
Since I changed this configuration file to no avail, I chose the cmd method to set it up and restart the database service.
cmd to enter the database
mysql -hlocalhost -uroot -p
Then enter the following command to view the upload limit size of the database
show VARIABLES like '%max_allowed_packet%';
Here is the parameter I changed to 50MB, the default should be 1,048,576, that is, 1MB is limited to 50MB
by set global max_allowed_packet = 5*1024*1024*10
setting the upload limit, then restart cmd and run the above show command, restart the mysql service and it will be fine.