'too many unstable restarts (16). Stopped. "errored" pm2 nodejs

Node version : 12

pm2 version : Latest 4.4

i have installed pm2 from below command

wget -qO- https://getpm2.com/install.sh | bash

My .js file

var http = require('http');

http.createServer(function (req, res) 
{
res.writeHead(200, {'Content-Type': 'text/plain'});

res.end('Hello World\n');

}).listen(8080, 'localhost');

console.log('Server running at http://localhost:8080/');

After running command npm2 start test.js ,it show status=Online for few seconds but after few seconds it show status=Errored

pm2 report

PM2 | 2020-06-13T14:51:43: PM2 log: Script /srv/test.js had too many unstable restarts (16). Stopped. "errored"



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source