How to prevent the node.js process from hanging up

problem description

node.js

the environmental background of the problems and what methods you have tried

try catch 
forever

related codes

/ / Please paste the code text below (do not replace the code with pictures)

what result do you expect? What is the error message actually seen?


May.14,2021

can't restart after hanging up? -A lot of data is stored in memory. After restart, the data in memory is gone


process.on('uncaughtException', function (err) {
    console.log('Caught exception: ' + err);
});

repair bug if you have bug. It's not impossible to find a way to cover up bug, but something will happen sooner or later


.

Daemon mode needs to be turned on when the NodeJS service is deployed to the server, that is, the process always runs in the background.

if the exception thrown is not caught by try {} catch (err) {}, the uncaughtException event handler prevents the process from exiting directly. However, when the process crashes caused by some underlying errors, uncaughtException is no longer applicable.

you can use PM2 to implement process management of NodeJS services. When a process exits abnormally, PM2 attempts to restart the process to ensure the stable operation of the service.

but: there is a lot of data stored in memory, and the data in memory is gone after reboot?

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e53cce-445b8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e53cce-445b8.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?