UbuntuUbuntu Based

How To Install Sails.js Framework on Ubuntu 22.04 LTS

Install Sails.js Framework on Ubuntu 22.04

In this tutorial, we will show you how to install Sails.js Framework on Ubuntu 22.04 LTS. For those of you who didn’t know, Sails.js is an MVC framework for Node.js similar to Ruby on Rails. It enables developers to rapidly assemble REST APIs, single-page apps, and many more. Sails.js is a flawless JavaScript solution that underpins varied front-end technologies and multiple databases concurrently.

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 22.04 (Jammy Jellyfish). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.

Prerequisites

  • A server running one of the following operating systems: Ubuntu 22.04, 20.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.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • 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 on Ubuntu 22.04 LTS Jammy Jellyfish

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 wget apt-transport-https gnupg2

Step 2. Installing Node.js on Ubuntu 22.04.

  • Install Node.js from NodeSource Repository.

By default, Node.js is not available on Ubuntu 22.04 base repository. Now run the following command below to add the NodeSource repository to your Ubuntu system:

wget -qO- https://deb.nodesource.com/setup_16.x | sudo -E bash

After adding the NodeSource repository to your system, install the Node.js using the Apt package manager:

sudo apt install nodejs
  • Install Node.js using NVM.

Now use the bash script to install NVM on your Ubuntu system:

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

Next, close and reopen your terminal or run the following command to load the nvm to your current session:

source $HOME/.bashrc

Using NVM, you can check which versions of Node.js are currently available:

nvm install --lts
nvm install node

Confirm the latest LTS version has been installed and run the command:

node -v

Additionally, you can check the version of NPM using the following command below:

npm -v

For additional resources on installing Node.js, read the post below:

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

By default, Sails.js is not available on Ubuntu 22.04 base repository. Now run the following command below to the Sails.js Framework using the NPM command:

npm -g install sails

Verify that the Sails.js framework is installed:

sails --version

Step 4. Create a Demo App.

Now run the following command to generate a demo application:

sails new idroot-app

Output:

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)

Type 1 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-app`!

Next, change the directory of the newly created application. The directory name is the same as your application and start the Sails app with the following command:

cd idroot-app
sails lift

You will get the following output:

info: Starting app...

 info: Initializing project hook... (`api/hooks/custom/`)
 info: Initializing `apianalytics` hook...  (requests to monitored routes will be logged!)
 info: ·• Auto-migrating...  (alter)
 info:    Hold tight, this could take a moment.
 info:  ? Auto-migration complete.

debug: Running v0 bootstrap script...  (looks like this is the first time the bootstrap has run on this computer)
 info:
 info:                .-..-.
 info:
 info:    Sails              <|    .-..-.
 info:    v1.5.3              |\
 info:                       /|.\
 info:                      / || \
 info:                    ,'  |'  \
 info:                 .-'.-==|/_--'
 info:                 `--'-------'
 info:    __---___--___---___--___---___--___
 info:  ____---___--___---___--___---___--___-__
 info:
 info: Server lifted in `/home/meilana/idroot-app`
 info: To shut down Sails, press <CTRL> + C at any time.
 info: Read more at https://sailsjs.com/support.

debug: -------------------------------------------------------
debug: :: Tue Sep 02 2022 10:34:46 GMT+0000 (Coordinated Universal Time)

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

Step 5. Create a Systemd Service for Sails.js.

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

sudo nano /etc/systemd/system/idroot-app.service

Add the following lines:

[Unit]
After=network.target

[Service]
Type=simple
User=navjot
WorkingDirectory=/home/meilana/idroot-app
ExecStart=/home/meilana/.nvm/versions/node/v16.17.0/bin/node app.js
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 enable idroot-app --now

Step 6. Configure Nginx as a Reverse Proxy.

First, install the Nginx on your Ubuntu using 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  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 7. Enable HTTPS on Nginx.

First, we install Certbot on Ubuntu 22.04 using the following command:

sudo snap install core
sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot

After complete install Certbot, now we set up Certbot for Nginx using the following command:

sudo apt install python3-certbot-nginx

Next, run the following command to start the creation of your certificate:

sudo certbot --nginx --agree-tos --redirect --hsts --staple-ocsp --email admin@your-domain.com -d www.your-domain.com

Let’s Encrypt certificates have 90 days of validity, and it is highly advisable to renew the certificates before they expire. To test that this renewal process is working correctly, you can run:

sudo certbot renew --dry-run

Step 8. Configure Firewall.

Now we set up an Uncomplicated Firewall (UFW) with Apache to allow public access on default web ports for HTTP and HTTPS:

sudo ufw allow OpenSSH
sudo ufw allow 'Apache Full'
sudo ufw enable

Step 9. Accessing Sails.js Framework Web Interface.

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

Install Sails.js Framework on Ubuntu 22.04 LTS Jammy Jellyfish

Congratulations! You have successfully installed Sails.js. Thanks for using this tutorial for installing the Sails.js Framework on Ubuntu 22.04 LTS Jammy Jellyfish 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 an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button