Hello World Node app on a DreamHost VPS using Passenger

Both the Apache and Nignx integrated Passenger module can now run Node apps on DreamHost. Passenger takes care of keeping the app running at all times. The bad news is that it does not allow for socket binding or streaming responses, which means no server sent events or two way socket multiplexing of data. Running something a Ghost blog is fine, however if your app really uses any of those technologies mentioned previously, you will have run your app on a standalone server and proxy to port 80.

First read up on how to set up NVM on the Dreamhost KB here https://help.dreamhost.com/hc/en-us/articles/217185397-Node-js-overview. Once you have your user and site up we can begin to create our simple app. For this tutorial, we will stick to a simple hello world application. This tutorial only applies to a DreamHost VPS, as node is not installed on shared (but can be and I will show you how in a future tutorial).

Make sure to enable passenger node support via the DreamHost panel. Visit https://panel.dreamhost.com/index.cgi?tree=domain.manage&and click the edit link to the right of the domain. Next check the passenger checkbox along with the node check box. There is another way to enable node support in Passenger via an .htaccess file that I show in the node on shared tutorial.

Now lets SSH into our site and user and then cd into the main site directory.

In this directory we will create an app.js file and paste the following contents.

Next visit the site in a browser and you will see hello world display on the page.

One thing to keep in mind, Passenger will automatically load an app.js file, however if the application uses a different file name, then you have to tell Passenger which file is used as the entry point. This can be done via an .htaccess file by adding the following three directives:

All three directives must be added or else Node will not be able to locate and load up the file.