Node.js永远与环境变量 [英] Node.js forever with environment variable

查看:131
本文介绍了Node.js永远与环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的服务器上运行的命令启动我的节点应用程序是:

The command I run on my server to start my node app is:

sudo IS_PROD=1 node app.js

我已经永远安装,但似乎不能传入环境变量。

I have forever installed but can't seem to pass in the environment variable.

sudo IS_PROD=1 forever node app.js

似乎没有办法。我尝试了几个品种。如何成功执行此命令或永久设置环境变量?

Doesn't seem to do the trick. I have tried several varieties of this. How do I either execute this command successfully or permanently set the environment variable?

推荐答案

首先你应该跳过 node 你在命令中的东西,它不应该在那里,你不应该能够执行。 永远的问题会使用 nodejs 。相反,你应该这样做;

First of all you should skip the node thing in you command, it should not be there, you should not be able to execute that. forever automatically starts your script using nodejs. Instead you should do like this;

sudo IS_PROD=1 forever app.js

可能你不是在前台启动服务器,而是要作为守护进程启动服务器。例如

Probably you, instead of starting your server in foreground, will want to start your server as a daemon. eg.

sudo IS_PROD=1 forever start app.js

这将在后台创建一个进程,该进程会监视您的节点应用程序,并在退出时重新启动它。有关详细信息,请参阅自述文件

This will create a process in the background that will watch your node app and restart it when it exits. For more information see the readme.

这两种方法都保留环境变量,就像您刚刚使用节点一样。

Both of these methods preserves the environment variables, just like when you are just using node.

这篇关于Node.js永远与环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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