LinuxTutorialsUbuntu

How To Install Sails.js Framework with Nginx on Ubuntu 20.04 LTS

Install Sails.js Framework with Nginx on Ubuntu 20.04

In this tutorial, we will show you how to install Sails.js Framework with Nginx on Ubuntu 20.04 LTS. For those of you who didn’t know, Sails.js is a Javascript framework for Node.js. It is used for developing real-time applications very quickly. Sails.js is designed to resemble the MVC architecture from frameworks like Ruby on Rails, but with support for the more modern, data-oriented style of web app development.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the Sails.js Framework on Ubuntu 20.04 (Focal Fossa). You can follow the same instructions for Ubuntu 18.04, 16.04, and any other Debian-based distribution like Linux Mint.

Prerequisites

  • A server running one of the following operating systems: Ubuntu 20.04, 18.04, 16.04, and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install Sails.js Framework with Nginx on Ubuntu 20.04 LTS Focal Fossa

Step 1. First, make sure that all your system packages are up-to-date by running the following apt commands in the terminal.

sudo apt update
sudo apt upgrade
sudo apt install curl wget gnupg2

Step 2. Installing Node.Js.

You simply need to add the PPA for the version you want to install Node.js to your system:

curl -sL https://deb.nodesource.com/setup_14.x | sudo -E bash -

To install, run the commands below:

sudo apt install nodejs

Once done, verify the installation by running:

node --version
npm --version

Step 3. Installing Sails.js Framework on Ubuntu 20.04.

Now we install Sails.js using the NPM command:

npm -g install sails

Next, we create your project using Sails.js with the following command:

sails new idroot-project

You’ll see a prompt to choose your project template:

Choose a template for your new Sails app:
 1. Web App  ·  Extensible project with auth, login, & password recovery
 2. Empty    ·  An empty Sails app, yours to configure
 (type "?" for help, or <CTRL+C> to cancel)
? 2

Type 2 and hit Enter to finish the installation:

 info: Installing dependencies...
Press CTRL+C to cancel.
(to skip this step in the future, use --fast)
 info: Created a new Sails app `idroot-project`!

After that, change the directory to idroot-project and start your application with the following command below:

cd idroot-roject
sails lift

Output:

info: Starting app...

 info: 
 info:                .-..-.
 info: 
 info:    Sails              <|    .-..-.
 info:    v1.4.3              |\
 info:                       /|.\
 info:                      / || \
 info:                    ,'  |'  \
 info:                 .-'.-==|/_--'
 info:                 `--'-------' 
 info:    __---___--___---___--___---___--___
 info:  ____---___--___---___--___---___--___-__
 info: 
 info: Server lifted in `/root/idroot-project`
 info: To shut down Sails, press  + C at any time.
 info: Read more at https://sailsjs.com/support.

debug: -------------------------------------------------------
debug: :: Sun Sept 23 2021 23:13:46 GMT+0000 (Coordinated Universal Time)

debug: Environment : development
debug: Port        : 1337
debug: -------------------------------------------------------

Step 4. Create a Systemd Service File for Sails.js.

Now create a systemd service file to manage the Sails.js application:

nano /lib/systemd/system/sails.service

Add the following lines:

[Unit]
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/root/myapp
ExecStart=/usr/bin/sails lift
Restart=on-failure

[Install]
WantedBy=multi-user.target

Save and close the file, then reload the systemd daemon to apply the changes:

sudo systemctl daemon-reload
sudo systemctl start sails
sudo systemctl enable sails

Step 5. Configure Nginx as a Reverse Proxy.

First, install the Nginx web server with the following command below:

sudo apt install nginx

Next, we create an Nginx virtual host configuration file for Sails:

nano /etc/nginx/conf.d/sails.conf

Add the following lines:

server {
 listen       80;
 server_name  sails.your-domain.com;
   location / {
     proxy_pass        http://localhost:1337/;
     proxy_set_header  Host $host;
     proxy_buffering   off;
   }
 }

Save and close the file, then restart the Nginx service to apply the configuration changes:

nginx -t
sudo systemctl restart nginx

Step 6. Configure Firewall.

Now we allow port 80 through the firewall:

sudo firewall-cmd --permanent --zone=public --add-port=80/tcp
sudo firewall-cmd --reload

Step 7. Accessing Sails.js Web Interface.

Once successfully installed, open your web browser and access the Sails.js web interface using the URL http://salis.your-domain.com. You should see the Sails.js default page on the following screen:

Install Sails.js Framework with Nginx on Ubuntu 20.04 LTS Focal Fossa

Congratulations! You have successfully installed Sails.js. Thanks for using this tutorial for installing the Sails.js Framework on Ubuntu 20.04 LTS Focal Fossa system. For additional help or useful information, we recommend you check the official Sails.js website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is a seasoned Linux system administrator with a wealth of experience in the field. Known for his contributions to idroot.us, r00t has authored numerous tutorials and guides, helping users navigate the complexities of Linux systems. His expertise spans across various Linux distributions, including Ubuntu, CentOS, and Debian. r00t's work is characterized by his ability to simplify complex concepts, making Linux more accessible to users of all skill levels. His dedication to the Linux community and his commitment to sharing knowledge makes him a respected figure in the field.
Back to top button