How do I restart automatically after a node crash?

when I was playing in the Chrome console, I accidentally made an error and the node process crashed
I have to restart node manually. How can I make node restart automatically? I just want to quickly verify some code on the console
in the following code, I deliberately did not catch the error and requested a file that does not exist. I hope it can be restarted quickly.

this is a basic server example, using debug mode to set up the environment
node --inspect aaa.js

var http = require("http");
http.createServer(function (req, res) {
  res.writeHead(200, {"Content-Type": "text/plain"});
  res.end("Hello World!");
}).listen(8080);
May.13,2022

the method of automatic restart is provided upstairs, so I won't say much about it. In fact, there is no need to restart, just do not exit, the specific way is to catch "uncaught exceptions":

process.on('uncaughtException', err => {
  console.error(err && err.stack)
});

pm2, forever and other process managers learn about


debug nodemon locally, and automatically restart


by modifying the code.

pm2 is recommended for management.

https://www.jianshu.com/p/f64...

you can learn about forever, which is very useful. After installation, start your project with forever to solve the problem


nodemon is recommended in the development phase

introduction to Nodemon

pm2 is recommended in the production phase

introduction to pm2

you can use pm2 or forever in the test phase

introduction to forever


the best toy ndb

gtihub: https://github.com/GoogleChro...

advantages:

  1. the error process does not crash
  2. code is updated automatically, similar to nodemon and pm2, but officially this uses no restart technology
  3. The
  4. code is updated bidirectionally. After modification in the debugger, the source file is also modified
  5. comes with a terminal
  6. refresh the environment with one click, just like a browser refresh

figure:


linux, Mac development environment:

  1. daemon tools such as supervisor and nodemon, which can be used to debug
  2. pm2 process monitoring tool, which can be used to publish projects
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-1b36f2a-2c05f.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-1b36f2a-2c05f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?