Installing Sails.js on managed hosting accounts
Learn how to install Sail.js on your web hosting account. Just follow our simple, step-by-step Sail.js setup instructions. Hosting.com makes it easy.
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:
-
Log in to your account using SSH.
-
At the command prompt, type the following commands:
mkdir ~/lib cd ~/lib npm install sails
-
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
-
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:
-
At the command prompt, type the following commands:
cd ~ sails new testProject
This creates a new Sails application named testProject.
-
Type the following command:
cd testProject/config
-
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,
Note
To run Sails on a shared server, you must choose an unused port, and the port number must be between 49152 and 65535 (inclusive).
-
Save the changes to the local.js file, and then exit the text editor.
-
Type the following command:
cd ~/public_html
-
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]
-
In both RewriteRule lines, replace xxxxx with the port you specified in the local.js file in step 3.
-
Save the changes to the .htaccess file, and then exit the text editor.
-
To start the Sails application, type the following commands:
cd ~/testProject nohup sails lift &
Note
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.
-
Use your web browser to visit your web site. If the Sails application is running, you see the Sails A brand new app page.
Tip
-
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.
Related Articles
Updated 1 day ago