PM2(Node.js)没有侦听指定的端口 [英] PM2 (Node.js) not listening on specified port
问题描述
我正在尝试在PM2上启动并运行Node / Express应用程序。我可以使用以下命令启动应用程序: npm start
I am trying to get a Node/Express application up and running on PM2. I can start the application fine with this command: npm start
这将在端口3000上启动应用程序。
This starts the app fine on port 3000.
如果我尝试用 pm2启动应用程序,请启动app.js
我在日志中得到以下信息:
If I try to start the application with pm2 start app.js
I get the following in the log:
{ online: true, success: true, pid: 10714, pm2_version: '0.8.15' }
2014-06-12T19:52:06.789Z : [[[[ PM2/God daemon launched ]]]]
2014-06-12T19:52:06.800Z : RPC interface [READY] on 6666:localhost
2014-06-12T19:52:06.801Z : BUS system [READY] on 6667:localhost
2014-06-12T19:52:06.978Z : Entering in node wrap logic (cluster_mode) for script /home/user/test/app.js
2014-06-12T19:52:07.115Z : /home/user/test/app.js - id0 worker online
在我的bin / www文件中,我有以下内容指定端口:
In my bin/www file I have the following specifying the port:
app.set('port', process.env.PORT || 3000);
我也尝试过运行 export PORT = 3000
以及bin / www中的以下内容:
As well as the following in bin/www:
app.set('port', 3000);
如果我运行 netstat -an | grep 3000
我什么都没回来。
If I run a netstat -an | grep 3000
I get nothing back.
推荐答案
对于任何使用Express的人来说,答案是运行此命令:
The answer to this, for anyone using Express, is to run this command:
pm2 start ./bin/www
我一直在运行 pm2 start app.js
哪条不起作用。
I had been running pm2 start app.js
which did not work.
这篇关于PM2(Node.js)没有侦听指定的端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!