This article describes steps one can take to install and use Sails.js framework on Ubuntu Linux.
Sails makes it easy to build custom, enterprise-grade Node.js apps, including real-time web applications.
Sails is designed to emulate the familiar MVC pattern of frameworks like Ruby on Rails, but with support for the requirements of modern app that includes salable data-driven APIs and more.
It supports databases such as MySQL, PostgreSQL, MongoDB, Redis and many other.
Below is how to install Sails.js on Ubuntu Linux.
How to install Sails.js on Ubuntu Linux
As described above, Sails makes it easy to build custom, enterprise-grade Node.js apps, including real-time web applications.
Below is how to install and use it on Ubuntu Linux.
To install Sails, you will need to first install Node.js using Node Version Manager (nvm).
Install NVM
Run the following command to download and install NVM. The current and latest version of NMM at the time of this post is 0.39.1.
Free to switch the version number in the line below when a new version is added.
curl -sL -o install_nvm.sh | bash install_nvm.sh
Next, run the commands below to register nvm command with your bash profile.
source ~/.bashrc
NVM should now be installed.
Install Node.js
Now that NVM is installed, use it to download and install Node.js. To install the latest stable version of Node.js, run the commands below.
nvm install --lts
Install Sails.js
At this point, NVM and Node.js are both installed. Run the commands below to install Sails globally.
npm -g install sails
Once installed, version Sails version number using the commands below.
sails --version
Create Sails app
Once Sails is installed, run the commands below to create your first app called geek-app.
sails new geek-app
When prompted to choose the type of app, choose Web App.
Next, change into the app directory, install npm and start the app.
cd geek-app npm install sails lift
Open your browser and browse to the server hostname or IP address followed by port number 1337 to see Sails web portal.
Create Sails systemd service
In order to quickly start and stop Sails services, create a systemd file. Run the commands below to create the file.
sudo sudo nano /etc/systemd/system/geek-app.service
Copy and paste the lines below into the file and save.
[Unit] After=network.target [Service] Type=simple User=richard WorkingDirectory=/home/richard/geek-app ExecStart=/home/richard/.nvm/versions/node/v16.17.1/bin/node app.js Restart=on-failure [Install] WantedBy=multi-user.target
Replace the values for the User, WorkingDirectory and ExecStart variables with your username, application path, and the path to your node application.
Also make sure the path for node is correct in your home directory.
Reload systemd daemon service and start Sails.
sudo systemctl daemon-reload sudo systemctl enable geek-app --now
Now you should be able to stop and start Sails using the commands below.
sudo systemctl stop geek-app sudo systemctl start geek-app
When you check the status, you should see something similar as below:
● geek-app.service Loaded: loaded (/etc/systemd/system/geek-app.service; enabled; vendor preset: enabled) Active: active (running) since Mon 2022-10-10 14:22:01 CDT; 8s ago Main PID: 22377 (node) Tasks: 22 (limit: 4626) Memory: 167.1M CPU: 3.127s CGroup: /system.slice/geek-app.service ├─22377 /home/richard/.nvm/versions/node/v16.17.1/bin/node app.js └─22385 grunt "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "> Oct 10 14:22:03 Ubuntu2204 node[22377]: info: ____---___--___---___--___---___--___-__ Oct 10 14:22:03 Ubuntu2204 node[22377]: info: Oct 10 14:22:03 Ubuntu2204 node[22377]: info: Server lifted in `/home/richard/geek-app` Oct 10 14:22:03 Ubuntu2204 node[22377]: info: To shut down Sails, press <CTRL> + C at any time. Oct 10 14:22:03 Ubuntu2204 node[22377]: info: Read more at Oct 10 14:22:03 Ubuntu2204 node[22377]: debug: ------------------------------------------------------- Oct 10 14:22:03 Ubuntu2204 node[22377]: debug: :: Mon Oct 10 2022 14:22:03 GMT-0500 (Central Daylight Time) Oct 10 14:22:03 Ubuntu2204 node[22377]: debug: Environment : development Oct 10 14:22:03 Ubuntu2204 node[22377]: debug: Port : 1337
Using reverse proxy
The most efficient way to use Sails is to run it behind a reverse proxy. Below are two posts that show you how to setup a reverse proxy with either Nginx or Apache.
You may also use Let’s Encrypt certificate with Sails. Below are two posts that may help you.
That should do it!
Conclusion:
This post showed you how to install and use Sails.js framework in Ubuntu Linux. If you find any error above or have something to add, please use the comment form below.