Sails Tutorial — Chapter 1
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 crmGo inside the created crm folder.
cd crmCreate a package.json file with defaults (-y).
npm init -yInstall the Sails framework (sails) as the dependency in this project.
npm i sailsAlso install the Nodemon (nodemon) to restart the server on changes as development dependency (-D).
npm i -D nodemonGo ahead and create a new file with name app.js.
touch app.jsOpen 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)!
Get Kiran Chauhan’s stories in your inbox
Join Medium for free to get updates from this writer.
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 devThe 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.







