如何在远程服务器上启动NodeJS进程? [英] How to start a NodeJS process on a remote server?

查看:524
本文介绍了如何在远程服务器上启动NodeJS进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个简单的NodeJS应用程序,现在将其移至AWS中的服务器.

I've created a simple NodeJS app which I have now moved up to a server in AWS.

我能够ssh进入服务器并启动应用程序,但是很明显,一旦我关闭终端,该过程就会停止.

I'm able to ssh into the server and start the application but obviously as soon as I close the terminal the process stops.

关闭终端后,如何启动NodeJS应用并使其运行?

How to I start my NodeJS app and keep it running after I've closed my terminal?

推荐答案

这不是特定的nodejs问题,尽管有特定的解决方案(例如

That's not a specific nodejs problem, although there are specific solutions (for example forever).

一个通用的解决方案是使用nohup启动它,该解决方案可在Linux上远程启动任何程序,并且在关闭会话时不会死机.这是一个示例,其中我启动节点并将标准输出和错误输出都重定向到server.log文件:

A generic solution to remotely start any program on linux and not have it die when you close the session is to launch it using nohup. Here's an example in which I launch node and redirect both the standard and error outputs into the server.log file :

nohup node main.js >> server.log 2>&1 < /dev/null & 

这篇关于如何在远程服务器上启动NodeJS进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆