Colin Stevenson
Colin Stevenson

Reputation: 551

Express.js App on Phusion Passenger - did not write a startup response in time

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.

Upvotes: 2

Views: 3147

Answers (3)

Phillip
Phillip

Reputation: 627

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);
}

Upvotes: 1

Kevin Hu
Kevin Hu

Reputation: 101

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.

Upvotes: 9

Colin Stevenson
Colin Stevenson

Reputation: 551

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

Upvotes: 4

Related Questions