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:
-
To create a symbolic link that enables you to run Sails from any directory in your account, type the following commands:
-
To confirm that Sails is installed and configured correctly, type the following command:
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:
This creates a new Sails application named testProject.
-
Type the following command:
-
Open the local.js file in your preferred text editor. Locate the following line:
Just after that line, add the following line, replacing xxxxx with the port on which the Sails application should run:
📘 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:
-
In your preferred text editor, create an .htaccess file and add the following lines:
- 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:
📘 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:
This command immediately stops all running Node.js applications.