New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

for express, should pm2 start app.js or bin/www? #2528

jiajianrong opened this Issue Nov 17, 2016 · 2 comments


2 participants
Copy link

jiajianrong commented Nov 17, 2016

I failed with the former but succeed with latter. I see the bin/www has content like below:

var app = require('../app');
var debug = require('debug')('trace_jinrong_58:server');
var http = require('http');

var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);

var server = http.createServer(app);

server.on('error', onError);
server.on('listening', onListening);

Seems it creates http server in bin/www.
When using 'pm2 start app.js', the process indeed started but I don't know the port.
How should I do to current use 'pm2 start app.js'? Thanks


This comment has been minimized.

Copy link

jiajianrong commented Nov 17, 2016

Seems this is a desired change from express 3 to express 4 - creating http server is moved from app.js to bin/www. But the pm2 releted document hasn't updated accordingly.
I suppose I should either 1) use 'pm2 start bin/www' or 2) append below code in app.js then use 'pm2 start app.js'

app.set('port', process.env.PORT || 3000);
var server = app.listen(app.get('port'), function() {
  debug('Express server listening on port ' + server.address().port);

This comment has been minimized.

Copy link

vmarchaud commented Nov 17, 2016

PM2 examples aren't focused on express, we just make a generic name. You should use pm2 start with the entry point of your application, in your case bin/www

@vmarchaud vmarchaud closed this Nov 17, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment