Atlantic.Net Blog

How To Install Sails.js Framework with Nginx on Arch Linux

Sails is a free, open-source, popular MVC framework for Node.js. It is built on Express and used for building scalable production-ready Node.js applications. It is very similar to the Ruby on Rails web framework used to quickly build REST APIs, single-page apps, and real-time apps. It has a powerful code generator that helps you to build your application with less coding.

This post will show you how to install Sails JS with Nginx on Arch Linux.

Prerequisites

  • A fresh Arch Linux server
  • A root password configured on your server
  • An IPV6 IP address associated with your instance

Step 1 – Configure Repository

By default, the default repository is outdated in Arch Linux, so you will need to modify the default mirror list. You can do it by editing the mirror list configuration file:

nano  /etc/pacman.d/mirrorlist

Remove all lines and add the following lines:

## Score: 0.7, United States
Server = http://mirror.us.leaseweb.net/archlinux/$repo/os/$arch
## Score: 0.8, United States
Server = http://lug.mtu.edu/archlinux/$repo/os/$arch
Server = http://mirror.nl.leaseweb.net/archlinux/$repo/os/$arch
## Score: 0.9, United Kingdom
Server = http://mirror.bytemark.co.uk/archlinux/$repo/os/$arch
## Score: 1.5, United Kingdom
Server = http://mirrors.manchester.m247.com/arch-linux/$repo/os/$arch
Server = http://archlinux.dcc.fc.up.pt/$repo/os/$arch
## Score: 6.6, United States
Server = http://mirror.cs.pitt.edu/archlinux/$repo/os/$arch
## Score: 6.7, United States
Server = http://mirrors.acm.wpi.edu/archlinux/$repo/os/$arch
## Score: 6.8, United States
Server = http://ftp.osuosl.org/pub/archlinux/$repo/os/$arch
## Score: 7.1, India
Server = http://mirror.cse.iitk.ac.in/archlinux/$repo/os/$arch
## Score: 10.1, United States
Server = http://mirrors.xmission.com/archlinux/$repo/os/$arch

Save and close the file, then update all the package indexes with the following command:

pacman -Syu

Step 2 – Install Node JS and NPM

First, install NVM on your system with the following command.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.2/install.sh | bash

You will get the following output.

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm

=> Close and reopen your terminal to start using nvm or run the following to use it now:

Next, run the following command to activate the NVM environment variable.

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm

Now, verify the NVM version using the following command.

nvm --version

Output.

0.39.2

Next, install the latest version of Node JS using the following command.

nvm install --lts

You will get the following output.

Installing latest LTS version.
Downloading and installing node v18.14.2...
Downloading https://nodejs.org/dist/v18.14.2/node-v18.14.2-linux-x64.tar.xz...
####################################################################################################################################### 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v18.14.2 (npm v9.5.0)
Creating default alias: default -> lts/* (-> v18.14.2)

To verify the Node JS version, run the following command.

node --version

Output.

v18.14.2

Next, find the Node JS installation path using the following command.

which node

You will get the following output.

/root/.nvm/versions/node/v18.14.2/bin/node

Next, use the above path to create a symbolic link for Node JS.

ln -s /root/.nvm/versions/node/v18.14.2/bin/node /usr/bin/node

Step 3 – Install Sails JS

You can use the NPM to easily install the Sails JS on your server.

npm -g install sails

You will see the following output.

added 230 packages in 10s

6 packages are looking for funding
  run `npm fund` for details
npm notice 
npm notice New patch version of npm available! 9.5.0 -> 9.5.1
npm notice Changelog: https://github.com/npm/cli/releases/tag/v9.5.1
npm notice Run npm install -g [email protected] to update!
npm notice 

Step 4 – Create a Sails JS Application

First, create a directory to hold Sails JS with the following command.

mkdir sails

Next, navigate to the Sails directory and create a Sails app with the following command.

cd sails
sails new app

You will be asked to select the 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)
? 1

Type 1 and press the Enter key to continue.

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

Next, change the directory to the app directory and start the Sails app with the following command.

cd app
sails lift

You will see 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.4              |\
 info:                       /|.\
 info:                      / || \
 info:                    ,'  |'  \
 info:                 .-'.-==|/_--'
 info:                 `--'-------' 
 info:    __---___--___---___--___---___--___
 info:  ____---___--___---___--___---___--___-__
 info: 
 info: Server lifted in `/root/sails/app`
 info: To shut down Sails, press  + C at any time.
 info: Read more at https://sailsjs.com/support.

debug: -------------------------------------------------------
debug: :: Fri Feb 24 2023 10:13:10 GMT+0000 (Coordinated Universal Time)

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

Press the CTRL+C to stop the application

Next, find the Sails installation path with the following command.

which sails

Output.

/root/.nvm/versions/node/v18.14.2/bin/sails

Use the above path to create a symbolic link of Sails binary.

ln -s /root/.nvm/versions/node/v18.14.2/bin/sails /usr/bin/sails

Step 5 – Create a Systemd Service File for Sails JS

Next, it is a good idea to create a systemd file to manage the Sails JS service.

nano /lib/systemd/system/sails.service

Add the following configurations.

[Unit]
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/root/sails/app
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.

systemctl daemon-reload

Next, start and enable the Sails service with the following command.

systemctl start sails
systemctl enable sails

You can check the status of the Sails service with the following command.

systemctl status sails

You will get the following output.

● sails.service
     Loaded: loaded (/usr/lib/systemd/system/sails.service; disabled; preset: disabled)
     Active: active (running) since Fri 2023-02-24 10:15:30 UTC; 4s ago
   Main PID: 56668 (node)
      Tasks: 22 (limit: 4700)
     Memory: 174.2M
     CGroup: /system.slice/sails.service
             ├─56668 node /usr/bin/sails lift
             └─56677 grunt

Feb 24 10:15:32 archlinux sails[56668]:  info:  ____---___--___---___--___---___--___-__
Feb 24 10:15:32 archlinux sails[56668]:  info:
Feb 24 10:15:32 archlinux sails[56668]:  info: Server lifted in `/root/sails/app`
Feb 24 10:15:32 archlinux sails[56668]:  info: To shut down Sails, press  + C at any time.
Feb 24 10:15:32 archlinux sails[56668]:  info: Read more at https://sailsjs.com/support.
Feb 24 10:15:32 archlinux sails[56668]: debug: -------------------------------------------------------
Feb 24 10:15:32 archlinux sails[56668]: debug: :: Fri Feb 24 2023 10:15:32 GMT+0000 (Coordinated Universal Time)
Feb 24 10:15:32 archlinux sails[56668]: debug: Environment : development
Feb 24 10:15:32 archlinux sails[56668]: debug: Port        : 1337
Feb 24 10:15:32 archlinux sails[56668]: debug: -------------------------------------------------------

Step 6 – Install Nginx for Sails JS

Next, you will need to install and configure Nginx as a reverse proxy for Sails JS. First, install the Nginx package using the following command.

pacman -S nginx-mainline

Next, start and enable the Nginx service with the following command.

systemctl start nginx
systemctl enable nginx

Next, create a directory to store Nginx virtual host.

mkdir /etc/nginx/sites-enabled

Next, create an Nginx configuration file for Sails JS.

nano /etc/nginx/sites-enabled/sails.conf

Add the following configuration.

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

Save the file, then edit the Nginx main configuration file.

nano /etc/nginx/nginx.conf

Add the following lines after http{:

server_names_hash_bucket_size 64;
include sites-enabled/*;

Save the file then verify the Nginx configuration.

nginx -t

You will get the following output.

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Finally, restart the Nginx service to apply the changes.

systemctl restart nginx

Step 7 – Access Sails JS Web UI

Now, open your web browser and access the Sails JS web interface using the URL http://sails.example.com. You should see the Sails JS registration page on the following screen.

Provide your name, email, password then click on the Create account button. You should see the Sails JS dashboard on the following screen.
Sails dashboard page

Conclusion

In this tutorial, we explained how to install Sails JS on Arch Linux. We also explained how to configure Nginx as a reverse proxy for Sails JS. You can now start deploying your Sails JS app on the production environment. You can now install Sails JS on dedicated server hosting from Atlantic.Net!

Get a $250 Credit and Access to Our Free Tier!

Free Tier includes:
G3.2GB Cloud VPS a Free to Use for One Year
50 GB of Block Storage Free to Use for One Year
50 GB of Snapshots Free to Use for One Year