Sails.js is a Node.js MVC framework inspired by Ruby on Rails

Sails.js is a Node.js MVC framework inspired by Ruby on Rails

<em>Originally I shared this material to&nbsp;</em><a href="https://syndicode.com/2018/06/19/sails-js-is-a-node-js-mvc-framework-inspired-by-ruby-on-rails/" target="_blank"><em>Syndicode blog</em></a><em>.</em>

Originally I shared this material to Syndicode blog.

If you have read my Rails digests, you wouldn't be surprised with my next find. Sails.js is a Node.js MVC framework inspired by Ruby on Rails that follows convention over configuration principle. Sail.js allows you to quickly build REST APIs, single-page apps, and real-time (WebSockets-based) apps. It makes extensive use of code generators that allow you to build your application with less writing of code — particularly of common code that can be otherwise scaffolded.

Sails.js is the most popular MVC (model–view–controller) framework for Node.js, 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.

What are Sails.js basic concepts?

  1. 100% JavaScript. Building on top of Sails means your app is written entirely in JavaScript, the language you and your team are already using in the browser.
  2. Any database. Sails bundles a powerful ORM, Waterline, which provides a simple data access layer that just works, no matter what database you're using.
  3. Powerful associations. You can assign different models to different databases, and your associations/joins will still work - even across NoSQL and relational boundaries. Sails has no problem implicitly/automatically joining a MySQL table with a Mongo collection and vice versa.
  4. Auto-generate REST APIs. You can run sails generate api dentist and you'll get an API that lets you search, paginate, sort, filter, create, destroy, update, and associate dentists. These blueprint actions also work with Websockets and any supported database out of the box.
  5. No additional code to support WebSockets. Incoming socket messages are automatically compatible with every route in your Sails app, as well as any existing Express routes/middleware. Normalization of parameters, the session, and the streaming interface are all taken care of. The code you write works with WebSockets and HTTP without doing any extra work.
  6. Declarative, reusable security policies. Simple, reusable middleware functions that run before your controllers and actions. Writing policies encourages encapsulation, that simplifies your business logic and reduces the total amount of code you need. Policies are interchangeable with Express/Connect middleware, and you can plug in popular npm modules like Passport. Also, your policies work for both WebSockets and HTTP automatically.
  7. Frontend agnostic. Sails.js is compatible with any frontend strategy: Angular, Backbone, iOS/ObjC, Android/Java, Windows Phone, or something else that hasn't been invented yet.
  8. Flexible asset pipeline. Your entire frontend asset workflow is completely customizable and comes with support for all of the great Grunt modules which are already out there.
  9. Sails.js is built on Node.js and uses Express for handling HTTP requests.

Main Sails.js features

  • it’s built on Express.js
  • it has real-time support with WebSockets
  • it takes a “convention over configuration” approach
  • it has powerful code generation, thanks to Blueprints
  • it’s database agnostic thanks to its powerful Waterline ORM/ODM
  • it supports multiple data stores in the same project
  • it has good documentation.

There are currently a few important cons, such as:



  • no support for JOIN query in Waterline
  • no support for SQL transactions until Sails v1.0 (in beta at the time of writing)
  • until version 1.0, it still uses Express.js v3, which is EOL (end of life)
  • development is very slow.

Learn how to generate a new Sails.js project, and then how to create an API by just generating models, adding some attributes then generate controllers here. Also, there you can compare it to Express.js. Because Sails.js sits on top of Express. Its ensemble of small modules works together to provide simplicity, maintainability, and structural conventions to Node.js apps.

Sails.js has other advanced concepts such as servicespoliciesblueprints and hooks. Discover them on your own on the official Sails.js site!


By :  Iren Korkishko


Angular 9 Tutorial: Learn to Build a CRUD Angular App Quickly

What's new in Bootstrap 5 and when Bootstrap 5 release date?

Brave, Chrome, Firefox, Opera or Edge: Which is Better and Faster?

How to Build Progressive Web Apps (PWA) using Angular 9

What is new features in Javascript ES2020 ECMAScript 2020

How to Use Express.js, Node.js and MongoDB.js

In this post, I will show you how to use Express.js, Node.js and MongoDB.js. We will be creating a very simple Node application, that will allow users to input data that they want to store in a MongoDB database. It will also show all items that have been entered into the database.

Node.js for Beginners - Learn Node.js from Scratch (Step by Step)

Node.js for Beginners - Learn Node.js from Scratch (Step by Step) - Learn the basics of Node.js. This Node.js tutorial will guide you step by step so that you will learn basics and theory of every part. Learn to use Node.js like a professional. You’ll learn: Basic Of Node, Modules, NPM In Node, Event, Email, Uploading File, Advance Of Node.