Friday, September 16, 2016

Notes from Sails tutorial - Part 1

Below are few benefits of it.

Auto generated API
Database ORM
Inbuilt task runner
Security code
Built-in web sockets in routes.
Unlike MEAN stack, where you need to create API's manually and do same repetitive thing again and again, Sails.js allows you to automatically create skeleton APIs. Just a single command, and you will have block of code generated to get you started.

Additionally, Sails.js provides database drivers for every major database systems such as MySQL, MongoDB, PostgreSQL. Sails.js uses Grunt task runner as the default task runner, and also provides an effective way to manage custom grunt tasks.

Furthermore, common security parameters such as CORS and CSRF are already included in Sails.js project. All you need to do is to enable them from respective files and your application is secured with the latest security standards.

Sails.js uses Express to handle HTTP operations and Socket.io to handle web socket messages. It provides web socket messages to your routes without configuring it in back-end or front-end layer.

The controllers and model folders are the most important. Controller contains every piece of the code your application needs to drive a backend system and communicate with the View or User interface.

Model contains how the object in data store will look like. So, if you are using a relational database, then it will be a table in database and JSON object in model file, or if you are using NoSQL databases such as MongoDB, then it will be collection under model.

The database connection is configured in config/connections. Since i was planning to use mongo db, it was like below 

someMongodbServer: {
    adapter: 'sails-mongo',
    host: 'localhost',
    port: 27017,
    // user: 'username',
    // password: 'password',
    database: ‘mymongodb’
  } 

user name and password is commented so that it does not ask for any 

in config/model.js, we can configure to use this connection and tell it to sails. 

connection: 'someMongodbServer',


references:

No comments:

Post a Comment