如何指定pm2的端口号 [英] How to specify a port number for pm2

查看:1970
本文介绍了如何指定pm2的端口号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用pm2来管理一个node.js集群

  pm2 start。 -i 3 

我目前在heroku上运行应用程序,并使用上述命令使用Procfile,但我不知道如何配置pm2以使用现有的PORT env var。像 pm2开始。 -p $ PORT



我错过了什么?

解决方案

你可以使用环境变量。
例如:

1)NODE_PORT = 3002 pm2 start -I 0 app.js


2)在应用中读取值:

console.log(process.env.NODE_PORT);



或者,如果您正在构建快速应用程序:

<1> PORT = 3002 pm2 start -I 0 ./bin/www


2)在启动应用程序时自动加载PORT。

I'm trying to use pm2 to manage a node.js cluster

pm2 start . -i 3

I'm currently running the app on heroku and using a Procfile with the above command, but I cannot figure out how to configure pm2 to use the existing PORT env var. Something like pm2 start . -p $PORT

What am I missing?

解决方案

You can use environment variable. For example:

1) NODE_PORT=3002 pm2 start -I 0 app.js

2) Read value in app:

console.log(process.env.NODE_PORT);

Or, if you are build express app:

1) PORT=3002 pm2 start -I 0 ./bin/www

2) Express load PORT automatically at start application.

这篇关于如何指定pm2的端口号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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