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


What is better to learn: Ruby on Rails or Node.js?

Node.js provide you with the service of modern tooling with the embrace of the more forward-looking way of developing complex apps compare to other programming techs. Node.jS is very simple to learn in case you're comfortable with JavaScript. Rails is a development tool which gives web developers a framework, providing structure for every code they write. The Rails framework helps developers to build websites and applications. 

Top 7 Most Popular Node.js Frameworks You Should Know

Top 7 Most Popular Node.js Frameworks You Should Know

Node.js is an open-source, cross-platform, runtime environment that allows developers to run JavaScript outside of a browser. In this post, you'll see top 7 of the most popular Node frameworks at this point in time (ranked from high to low by GitHub stars).

Node.js is an open-source, cross-platform, runtime environment that allows developers to run JavaScript outside of a browser.

One of the main advantages of Node is that it enables developers to use JavaScript on both the front-end and the back-end of an application. This not only makes the source code of any app cleaner and more consistent, but it significantly speeds up app development too, as developers only need to use one language.

Node is fast, scalable, and easy to get started with. Its default package manager is npm, which means it also sports the largest ecosystem of open-source libraries. Node is used by companies such as NASA, Uber, Netflix, and Walmart.

But Node doesn't come alone. It comes with a plethora of frameworks. A Node framework can be pictured as the external scaffolding that you can build your app in. These frameworks are built on top of Node and extend the technology's functionality, mostly by making apps easier to prototype and develop, while also making them faster and more scalable.

Below are 7of the most popular Node frameworks at this point in time (ranked from high to low by GitHub stars).

Express

With over 43,000 GitHub stars, Express is the most popular Node framework. It brands itself as a fast, unopinionated, and minimalist framework. Express acts as middleware: it helps set up and configure routes to send and receive requests between the front-end and the database of an app.

Express provides lightweight, powerful tools for HTTP servers. It's a great framework for single-page apps, websites, hybrids, or public HTTP APIs. It supports over fourteen different template engines, so developers aren't forced into any specific ORM.

Meteor

Meteor is a full-stack JavaScript platform. It allows developers to build real-time web apps, i.e. apps where code changes are pushed to all browsers and devices in real-time. Additionally, servers send data over the wire, instead of HTML. The client renders the data.

The project has over 41,000 GitHub stars and is built to power large projects. Meteor is used by companies such as Mazda, Honeywell, Qualcomm, and IKEA. It has excellent documentation and a strong community behind it.

Koa

Koa is built by the same team that built Express. It uses ES6 methods that allow developers to work without callbacks. Developers also have more control over error-handling. Koa has no middleware within its core, which means that developers have more control over configuration, but which means that traditional Node middleware (e.g. req, res, next) won't work with Koa.

Koa already has over 26,000 GitHub stars. The Express developers built Koa because they wanted a lighter framework that was more expressive and more robust than Express. You can find out more about the differences between Koa and Express here.

Sails

Sails is a real-time, MVC framework for Node that's built on Express. It supports auto-generated REST APIs and comes with an easy WebSocket integration.

The project has over 20,000 stars on GitHub and is compatible with almost all databases (MySQL, MongoDB, PostgreSQL, Redis). It's also compatible with most front-end technologies (Angular, iOS, Android, React, and even Windows Phone).

Nest

Nest has over 15,000 GitHub stars. It uses progressive JavaScript and is built with TypeScript, which means it comes with strong typing. It combines elements of object-oriented programming, functional programming, and functional reactive programming.

Nest is packaged in such a way it serves as a complete development kit for writing enterprise-level apps. The framework uses Express, but is compatible with a wide range of other libraries.

LoopBack

LoopBack is a framework that allows developers to quickly create REST APIs. It has an easy-to-use CLI wizard and allows developers to create models either on their schema or dynamically. It also has a built-in API explorer.

LoopBack has over 12,000 GitHub stars and is used by companies such as GoDaddy, Symantec, and the Bank of America. It's compatible with many REST services and a wide variety of databases (MongoDB, Oracle, MySQL, PostgreSQL).

Hapi

Similar to Express, hapi serves data by intermediating between server-side and client-side. As such, it's can serve as a substitute for Express. Hapi allows developers to focus on writing reusable app logic in a modular and prescriptive fashion.

The project has over 11,000 GitHub stars. It has built-in support for input validation, caching, authentication, and more. Hapi was originally developed to handle all of Walmart's mobile traffic during Black Friday.

Difference between AngularJS, React, Ember, Backbone, and Node.js.

The most common thing between all of them is that they are Single Page Apps. The SPA is a single page where much of the information remains the same and only some piece of data gets modified when you click on other categories/option.