2

I am trying to run an express.js app on a server running Phusion Paggenger (apache) and am seeing the error "An error occurred while starting the web application: it did not write a startup response in time." after the request times out. I've read through https://github.com/phusion/passenger/wiki/Debugging-application-startup-problems but this seems a bit obscure. My express app is as bare-bones as possible so I'm wondering if anyone knows if there may be a component specific to express that might cause this. I have been able to run a plain node.js app with the same setup on the server.

Colin Stevenson
  • 541
  • 5
  • 7

3 Answers3

9

If you used the express-generator command to set up your project, you might see if pointing your Virtual Host configuration file's PassengerStartupFile line to bin/www instead of app.js does the trick instead of explicitly calling app.listen in the app.js file. Phusion Passenger's documentation does not address this specific convention adopted by ExpressJS. You can read some about this bin/www startup convention on Express's Moving to 4.x guide. Seemed to work for me.

Kevin Hu
  • 91
  • 1
  • 4
  • 1
    I had a similar problem for standalone Passenger with an Express app made with the express-generator, and started the app successfully with `passenger start --startup-file bin/www`. – Mallory-Erik Aug 16 '16 at 15:25
  • 1
    On my DreamHost shared server, this setting is in .htaccess. I just added `PassengerStartupFile bin/www` to `.htaccess` and restrted and that did the trick. – Bennett McElwee May 08 '21 at 01:07
4

It seems that you need to explicitly call app.listen within app.js. Specifically, I do this only when in production:

if (app.get('env') === 'production') {
    app.listen(3000);
}

at the end of app.js

Andy Ford
  • 8,410
  • 3
  • 26
  • 36
Colin Stevenson
  • 541
  • 5
  • 7
1

If you are getting here from google. This is now documented with Passenger: https://www.phusionpassenger.com/library/indepth/nodejs/reverse_port_binding.html

A working example of a simple express app is below:

if (typeof(PhusionPassenger) != 'undefined') {
    PhusionPassenger.configure({ autoInstall: false });
}

var express = require('express');
var app = express();
app.get('/', function(req, res){
    var body = 'Hello World';
    res.setHeader('Content-Type', 'text/plain');
    res.setHeader('Content-Length', body.length);
    res.end(body);
});

if (typeof(PhusionPassenger) != 'undefined') {
    app.listen('passenger');
} else {
    app.listen(3000);
}
Phillip
  • 607
  • 5
  • 9