如何在远程服务器上启动NodeJS进程?

编程入门 行业动态 更新时间:2024-10-24 20:14:27
本文介绍了如何在远程服务器上启动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进程?

本文发布于:2023-06-10 22:52:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/620787.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:进程   器上   如何在   NodeJS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!