How to install Sails.js on managed hosting accounts

This article describes how to install Sails.js on a managed hosting account. Sails.js is a web framework that enables you to quickly create Node.js applications.

Step 1: Install Node.js and npm

Sails.js runs on top of Node.js, so the first step is to install Node.js and npm (the Node.js package manager) on your account. For step-by-step instructions about how to do this, please see this article.

Step 2: Install Sails.js

After you install Node.js on your account, you are ready to install Sails. To do this, follow these steps:

  1. Log in to your account using SSH.
  2. At the command prompt, type the following commands:
    mkdir ~/lib
    cd ~/lib
    npm install sails
  3. To create a symbolic link that enables you to run Sails from any directory in your account, type the following commands:

    cd ~/bin
    ln -s ../lib/node_modules/sails/bin/sails.js sails
    
  4. To confirm that Sails is installed and configured correctly, type the following command:

    sails --version
    

    Sails displays the version number.

Step 3: Create a Sails.js application

After you install Sails, you are ready to create a Sails.js application and integrate it with the web server. To do this, follow these steps:

  1. At the command prompt, type the following commands:
    cd ~
    sails new testProject
    

    This creates a new Sails application named testProject.

  2. Type the following command:

    cd testProject/config
  3. Open the local.js file in your preferred text editor. Locate the following line:

      // port: process.env.PORT || 1337,
    

    Just after that line, add the following line, replacing xxxxx with the port on which the Sails application should run:

      port: xxxxx,
    
    To run Sails on a shared server, you must choose an unused port, and the port number must be between 49152 and 65535 (inclusive).
  4. Save the changes to the local.js file, and then exit the text editor.
  5. Type the following command:

    cd ~/public_html
  6. In your preferred text editor, create an .htaccess file and add the following lines:

    RewriteEngine On
    RewriteRule ^$ http://127.0.0.1:xxxxx/ [P,L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ http://127.0.0.1:xxxxxx/$1 [P,L]
  7. In both RewriteRule lines, replace xxxxx with the port you specified in the local.js file in step 3.
  8. Save the changes to the .htaccess file, and then exit the text editor.
  9. To start the Sails application, type the following commands:

    cd ~/testProject
    nohup sails lift &
    
    The & places the command in the background, and the nohup command ensures that the application continues running even if you log out of the current terminal session.
  10. Use your web browser to visit your web site. If the Sails application is running, you see the Sails A brand new app page.

    • If the Sails application fails to start, the port you chose may already be in use. Check the application log or nohup.out file for error codes like EADDRINUSE that indicate the port is in use. If it is, select a different port number for your application, update the local.js and .htaccess files with the new port number, and then try again.
    • To stop a currently running Sails application, type the following command:
      pkill node

      This command immediately stops all running Node.js applications.

More Information

To view the official Sails.js documentation, please visit http://sailsjs.org/documentation.

Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.

We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.