如何将一个node.js服务器作为守护进程启动? [英] How does one start a node.js server as a daemon process?
本文介绍了如何将一个node.js服务器作为守护进程启动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Python Twisted中,您具有twistd
命令,该命令可以帮助您解决许多与运行应用程序有关的事情(例如,对其进行守护进程).
In Python Twisted, you have the twistd
command that helps you with a number of things related to running your application (daemonize it for example).
您如何守护 node.js 服务器,使其即使在当前会话关闭后也可以运行?
How do you daemonize a node.js server so that it can run even after the current session is closed?
感谢您的帮助
推荐答案
永远回答了您的问题
$ curl https://npmjs.org/install.sh | sh
$ npm install forever
# Or to install as a terminal command everywhere:
$ npm install -g forever
用法
从命令行永久使用
$ forever start server.js
使用Node.js中的Forever实例
var forever = require('forever');
var child = new forever.Forever('your-filename.js', {
max: 3,
silent: true,
args: []
});
child.on('exit', this.callback);
child.start();
这篇关于如何将一个node.js服务器作为守护进程启动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文