2016-10-02 20:48:00

What Is Sails.js?

As SailsJS defined him self in offecial web site:

"Sails makes it easy to build custom, enterprise-grade Node.js apps. It is designed to emulate the familiar MVC pattern of frameworks like Ruby on Rails, but with support for the requirements of modern apps: data-driven APIs with a scalable, service-oriented architecture. It's especially good for building chat, realtime dashboards, or multiplayer games; but you can use it for any web application project - top to bottom."



One of the best part of Sails is simplicity.

for example if you need to connect it to mongo just you need to install sails-mongo adapter by

$ npm install sails-mongo --save

and set connection configuration in config/connections.js like below:

module.exports.connections = {

  someMongoDb: {
    adapter: 'sails-mongo',
    host: 'localhost', // defaults to `localhost` if omitted
    port: 27017, // defaults to 27017 if omitted
    user: 'username_here', // or omit if not relevant
    password: 'password_here', // or omit if not relevant
    database: 'database_name_here' // or omit if not relevant

Also Sails ORM able to connect to RDBMS and noSQL like Mongo and Neo4j document and graph base databases.

There is great documentation for this framework in official website.

 I love sails development CLI to create project, model and controller.

unfortunately it may there is no way to create model from exists tables in db. if you interest in to create npm library I appriciated and say thank you :)

As you know javascript is asyncronous language you may need some 3rd party libraries like async

to run your code as you order it.

for example:



one: function(callback) { setTimeout(function() { callback(null, 1); }, 200); },

two: function(callback){ setTimeout(function() { callback(null, 2); }, 100); }

}, function(err, results) { // results is now equal to: {one: 1, two: 2}



 For last thing that I would like to mention is create an example of  controller:

module.exports = {
  hi: function (req, res) {
    return res.send('Hi there!');
  bye: function (req, res) {
    return res.redirect('');

I hope you enjoy with Sails.jS.


Tags Cloud