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


node-js ruby-on-rails

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

How to Hire Node.js Developers And How Much Does It Cost?

A Guide to Hire Node.js Developers who can help you create fast and efficient web applications. Also, know how much does it cost to hire Node.js Developers.

Hands on with Node.Js Streams | Examples & Approach

The practical implications of having Streams in Node.js are vast. Nodejs Streams are a great way to handle data chunks and uncomplicate development.

Explain Ruby on rails MVC

Our Ruby on Rails Training will provide you to learn about Rails and web applications development with realty. Our Ruby on Rails Course also includes live sessions.

Node.js Performance: Node.js vs. Io.js

You may already be aware that Raygun uses Node.JS for our API nodes that receive your precious crash reporting data (we also do node.js crash reporting if you’re interested). We’ve peaked in the past at more than 110,000 requests per second coming...