Steps to Setup Sails.js Framework on Ubuntu

Sails.js is a free & open source MVC framework for Node.js.It helps to build custom,enterprise-grade Node.js applications.It supports scalable,WebSockets, service-oriented architecture,multiple data stores in the same project and provides basic security and role-based access control.

Prerequisite:

  • Ubuntu machine with Sudo privileges.

There are some steps to setup Sails.js Framework on Ubuntu:

Step 1: Update the system.

apt update

Step 2: Install Node.js

  • Install the required packages.

apt-get install curl wget gnupg2

  • Add the Node source repository.

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

  • Install nodejs.

apt install nodejs

  • Check the version of node & npm.

node --version
npm --version

  • Here is the command output.

Step 3: Install Sails.js framework.

npm -g install sails

  • Here is the command output.

Step 4: Create a new project.

sails new example-project

  • To choose a template for Sails application.

  • Type 2 & Hit the enter.

  • After that,change the directory.

cd example-project

  • Start the application.

sails lift

  • Here is the command output.

  • Press Ctrl+c to shut down the sails.

Step 5: Create a systemd service file.

vim /lib/systemd/system/sails.service

  • Add the following lines.

[Unit]
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/home/ubuntu/example-project  ### path of project###
ExecStart=/usr/bin/sails lift
Restart=on-failure
[Install]
WantedBy=multi-user.target

  • Here is the command output.

  • Save & Close the file.
  • Reload the systemd daemon.

systemctl daemon-reload

  • Start & Enable the Sails.js service.

systemctl start sails
systemctl enable sails

  • Check the status of the Sails.js service.

systemctl status sails

  • Here is the command output.

  • Open the following port number in UFW firewall.

ufw allow 1337

Step 6: Open Sails.js Framework Web Interface.

http://server-ip:1337

  • Here is the output.

Leave a Reply

Your email address will not be published.