Sails Tutorial — Chapter 1

Kiran Chauhan
2 min readAug 18, 2023

We are going to build the sample Sails.js or Sails application from the scratch with some unusual steps (for learning). At the end, we will have the small working CRM application. Without further ado, let’s get started.

Create a folder with name crm.

mkdir crm

Go inside the created crm folder.

cd crm

Create a package.json file with defaults (-y).

npm init -y

Install the Sails framework (sails) as the dependency in this project.

npm i sails

Also install the Nodemon (nodemon) to restart the server on changes as development dependency (-D).

npm i -D nodemon

Go ahead and create a new file with name app.js.

touch app.js

Open this file and write the following code.

const sails = require('sails');

sails.lift();

We first required the sails package and then called the .lift function. That’s it (in terms of code setup to use the Sails)!

Open package.json file and add two scrips — one to run app.js with node and second to run app.js with nodemon (I will add dev first and then start to write the scripts in alphabetic order).

{
"name": "crm",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"dev": "nodemon app.js",
"start": "node app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"sails": "^1.5.7"
},
"devDependencies": {
"nodemon": "^3.0.1"
}
}

Also, change the main file from index.js to app.js.

{
"name": "crm",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"dev": "nodemon app.js",
"start": "node app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"sails": "^1.5.7"
},
"devDependencies": {
"nodemon": "^3.0.1"
}
}

In the terminal, run the dev script.

npm run dev

The application is running at http://localhost:1337. Open this URL in the browser and you should see ‘Not Found’ with 404 status code. This is obvious as we haven’t write any code for the root route. But, the important thing is you just wrote the Sails application in up and running mode with just two lines of code in app.js file. Rest of the things were setup!

Take a break and read the second article in this series at this link.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Kiran Chauhan
Kiran Chauhan

Written by Kiran Chauhan

I design software with and for people.

No responses yet

Write a response