Quickstart: Node.js + Phusion Passenger

This 5 minute tutorial teaches you to start your application in a Phusion Passenger server, in development mode. Feel what Passenger is and how it works.

Are you looking to deploy your app to production with Passenger, maybe in combination with Nginx or Apache? Take a look at the deployment tutorial.

Table of contents

  1. Loading...

What is Passenger?

Passenger is an open source web application server. It handles HTTP requests, manages processes and resources, and enables administration, monitoring and problem diagnosis.

Passenger is very easy to use, makes deploying in production much easier and is scalable. If you aren't already familiar with the benefits, you can learn more about them.

This tutorial doesn't go very deep into Passenger's concepts. Instead, it serves to get you started as quickly as possible. When you're done with this tutorial, we'll explain the concepts in more detail.

Install Passenger

Preparing the example application

In this tutorial we will use an example "hello world" application, utilizing Connect.js:

$ git clone https://github.com/phusion/passenger-nodejs-connect-demo.git
$ cd passenger-nodejs-connect-demo
$ npm install

Running the server

The simplest way to run your app is with the node command:

$ node app.js

Passenger can be used the same way as the node command: you run your app with passenger start and two extra command line options:

$ passenger start --app-type node --startup-file app.js
======= Phusion Passenger Standalone web server started =======
PID file: /Users/phusion/myapp/passenger.3000.pid
Log file: /Users/phusion/myapp/passenger.3000.log
Environment: development
Accessible via: http://0.0.0.0:3000/

You can stop Phusion Passenger Standalone by pressing Ctrl-C.
===============================================================
If you run your app with a higher level command like npm start, you can find out what --startup-file to specify by looking at package.json. It should be whatever is behind the node command.

As you can see in the output, Passenger is now serving your app on http://0.0.0.0:3000/. So if you go to that URL, you will should see your application:

$ curl http://0.0.0.0:3000/
...your app's front page HTML...

Passenger is polyglot

Passenger supports apps in multiple programming languages. That's why you need to specify what language you're using. The --app-type node option does just that.

Reversed port binding

Normally, a Node.js app binds a server socket on a certain port by calling listen() on an http.Server object. But when run in Passenger, this control is inversed. The user that invokes the passenger command specifies what address and port to listen on, and Passenger makes sure your app does so.

Most of the time, reverse port binding just works. But if your app creates multiple http.Server objects, then you will confuse the reserve port binding system, and you'll have to give it some hints.

Reverse port binding will be covered in Basics part 2: fundamental concepts -> The "application server concept" and in the In-depth guide.

Logs

Passenger prints its own logs not only to the terminal, but also to a log file. During startup, Passenger tells you what log file it used. This is typically passenger.XXXX.log.

There may also be application logs, generated either by your app or by the framework you're using. These logs are completely separate from Passenger's own logs. If the application logs are printed to stdout or stderr, then Passenger will display them. Otherwise, it is up to you to manually view application log files, e.g. with the Unix tail tool on the corresponding files.

Stopping the server

If you stop Passenger, Passenger will stop your app.

There are two ways to stop the server. The first is by pressing Ctrl-C in the terminal.

$ passenger start --app-type node --startup-file app.js
...
(press Ctrl-C here)
Stopping web server... done!

The second way is by starting a seperate terminal, changing the working directory to your application, and running passenger stop:

$ cd /path-to-your-app
$ passenger stop

Conclusion

Achievement unlocked. Image taken from https://openclipart.org/detail/60109/award-symbol-by-sheikh_tuhin

Congratulations! Now that you've passed this tutorial and seen Passenger in action, you may be interested in intermediate-level tutorials.

Next step

You may now be interested in follow-up tutorials.

Basics

Learn what Passenger is, how it fits in the stack, its fundamental concepts and its basic usage. Focuses mainly on development rather than production.

Read this
Deployment

Learn how easy it is to setup a server and how to deploy your app to production. No worries, we walk you through from the beginning to the end.

Read this

...or go back to the Library index.