Node.js overview

Node.js is a newer runtime environment that has become very popular among web developers. It uses JavaScript, traditionally a front end programming language on the server side.

Can Node.js be used on shared servers?

No. DreamHost does not support Node.js on shared web servers, as the security setup on DreamHost shared servers is incompatible with compiling or running Node.js.

If you try to compile Node.js on one of the shared web servers, your user will automatically be banned through grsec (taking down all the PHP websites that run under that user) and the server will have to be rebooted before your user can be unbanned. If you do it one more time, you will be forced to move to a VPS.

DreamHost's VPS and Dedicated servers can run Node.js just fine.

Deploying Node.js with Passenger using the DreamHost panel

Visit the following article to learn how to deploy Node.js with Passenger in the panel:

Installing a custom version of NVM and Node.js

DreamHost support is unable to assist with custom installations. The directions below will explain how to install Node.js but if you find anything is not working as intended, you must contact a developer for further assistance.

The following steps use Node Version Manager to install.

  1. Check the version of Passenger running on your private server. The server must run version 4.0.37 or later.
    [server]$ dpkg -l | grep passenger
  2. Visit the following page to determine what version of NVM to install:
  3. Run the following command to download NVM. Change the version number as needed:
    [server]$ curl -o- | bash
    • This command installs NVM into a new directory under your user named /.nvm
    • This command also adds the following to your .bashrc file:
    export NVM_DIR="/home/exampleuser/.nvm"
    [ -s "$NVM_DIR/" ] && . "$NVM_DIR/"  # This loads nvm
  4. Open your .bash_profile:
    [server]$ nano $HOME/.bash_profile
  5. Insert the following into your .bash_profile file:
    . $HOME/.bashrc
  6. You are prompted to save the file.
  7. Click the Enter button to save.
  8. Finally, click Ctrl  + X to exit 'nano' and return to your shell.
  9. Run the following to allow your current Shell session to use NVM:
    [server]$ source $HOME/.bash_profile
  10. To test if you can now use NVM, run the following which should respond with the version you have installed:
    [server]$ nvm --version
  11. Check which versions of Node.js are available:
    [server]$ nvm ls-remote
  12. Install any version of Node.js you wish:
    [server]$ nvm install 6.10.0
  13. Check which version of Node.js is running by entering the following:
    [server]$ node -v

Node Package Manager

At this point you have NVM and Node.js installed and active. Node Package Manager is also installed with Node.js. Visit the following page for further details on npm:

Check the version by running the following command:

[server]$ npm -v

To update npm to the latest version, run the following command:

[server]$ npm install npm@latest -g

Check the directory NPM writes to. Run the following command:

[server]$ npm config get prefix

If you installed NVM as shown above, you'll see the directory response as the /.nvm folder under your current user.

Installing packages

View the following page for instructions on how to install packages locally or globally:

Testing Node.js

Now that you have installed Node.js you can create a simple test script to confirm if it's functioning.

Simple 'Hello World!' script

Create and run this script within your terminal:

  1. Create a file named HelloWorld.js, and then add the following in the file:
    console.log('Hello World!');
  2. Run the following in your terminal to run the script:
    [server]$ node HelloWorld.js
    Hello World!

    If correctly installed you will see the console respond with Hello World!

Website example

You can also create a basic HTTP server to load a site.

  1. Create a file in your web directory titled server.js, and then add the following code in the file:
    var http = require("http");
    http.createServer(function(request, response) {
      response.writeHead(200, {"Content-Type": "text/plain"});
      response.write("Hello World");
    • This HTTP server will listen on port 8888.
  2. Start the server by running the following:
    [server]$ node server.js
  3. If you have enabled Node.js in the panel, you can just visit your site to see the file functioning. If you have not enabled Node.js in the panel, visit the page in a browser with port 8888 appended to the end. For example,

    If running correctly, your site will display the text Hello World!.

See also

Internal links

External links

Did this article answer your questions?

Article last updated .