我正在尝试在 PM2 上启动并运行 Node/Express 应用程序。我可以使用以下命令启动应用程序:npm start
这会在端口 3000 上启动应用程序。
如果我尝试使用 pm2 start app.js
启动应用程序,我会在日志中看到以下内容:
{ 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 文件中,我指定了以下端口:
app.set('port', process.env.PORT || 3000);
我也试过运行 export PORT=3000
以及bin/www中的以下内容:
app.set('port', 3000);
如果我运行 netstat -an | grep 3000
我什么也得不到。
最佳答案
对于任何使用 Express 的人来说,答案是运行以下命令:
pm2 启动 ./bin/www
我一直在运行 pm2 start app.js
,但没有成功。
关于javascript - PM2(Node.js)未监听指定端口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24192971/