Sails.js Basics and Installation
Node.js: Node.js is an open-source and cross-platform runtime environment for executing JavaScript code outside a browser. You need to remember that NodeJS is not a framework and it’s not a programming language. Most of the people are confused and understand it’s a framework or a programming language. We often use Node.js for building back-end services like APIs like Web App or Mobile App.
Sails.js: Sails.js is a Node.js framework that is built on top of Express.js and a real-time Model-View-Controller(MVC) framework for Node.js. Sails are alike 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.
Creating a basic Sails.js App via NPM(Node Package Manager)
-
Step 1: Make an empty project folder. In command prompt(cmd)/terminal, run npm init to initialize package.json file:
>> npm init -y // The -y can be added to gain default settings in package.json
npm init in our project directory
-
Step 2: This usually takes about 48 seconds depending on your internet connection. You can optionally install nodemon for hot reloading. To install Sails.js.
>> npm install sails -g // The -g installs the library globally
Installing sails
-
Step 3: To generate a new app, just change directory (cd) into the directory where you want it to be, and type:
>> sails new sails-project
We’ll see a prompt to choose your project template as shown below:
new sails project
-
Step 4: Type 1 (or press enter) to start with the default “Web App” template that includes essential features like login, password recovery, emails, and billing. Or, if you want to start from scratch with an empty project, choose 2 for a classic Sails app.
Once you’ve chosen your template, you’ll need to wait a moment for some dependencies to install. Then, to take a look at your new Sails app:
>> cd sails-project >> sails lift
Starting server via sails
-
In the browser on localhost:1337 port, we get the below-rendered brand new homepage:
Final setup
Reference: https://sailsjs.com/get-started
Please Login to comment...