Sails vs Trails

Hi guys !

I hear a lot of people who ask What’s the differences between Sails and Trails ? or Why should I use Trails instead of Sails ? so I decide to explain my vision and things I have seen between these two Node.js frameworks.
I will not tell you one is better than the other, I will let you judge about this because it will depend of your needs and philosophy.

Definition

Here are definitions taking from officials github repos :

Sails : Sails.js is a web framework that makes it easy to build custom, enterprise-grade Node.js apps. It is designed to resemble the MVC architecture from frameworks like Ruby on Rails, but with support for the more modern, data-oriented style of web app development. It’s especially good for building realtime features like chat.

Trails : Trails is a modern, community-driven web application framework for node.js. It builds on the pedigree of Rails and Grails to accelerate development by adhering to a straightforward, convention-based, API-driven design philosophy.

I will add that Trails is not a fork of Sails, in fact 0 line of code come from Sails. Trails was full rewrite and is a new fresh framework.

I will not keep from you that these two frameworks have the same functionalities, they are :
* Generate automatic REST API from models
* MVC structure
* Support websockets for real time
* Support multiple databases
* Have plugin system
* Have policies to secure
* Front-end agnostic
* 100% JS

Differences

1) File loading

Sails

When you start using Sails, it’s magic you put your files under api and start your server and Sails load them automatically. It also loads config automatically. That’s cool for developing a prototype quickly, but loading all these file take time and can slow down server start (yes #perfmatters ^^).

Trails

In Trails it’s quite different, nothing is loaded automaticcaly, if you look a Trails project you can see in each directory an index.js, if you take a look at it you can see it only loads each file. Like this if you want to exclude some files from Trails you can, it will only load the files put in the index.js. By default if you use the yo generator to generate your files it will add it automatically under the index.js, if you don’t, don’t forget to add it on it or it will be ignored. Mistake can append because of this. With this kind of loading system that’s mean if you don’t want an MVC architure, you can change it to whatever you want, but files must be in the index.js at the end.

2) Web server

Sails

As we speak, Sails use express 3 as web server, I don’t have to remind you that this version of express is more de deprecated, it’s even not maintened anymore by the express team. They work to migrate to express 5 (no 4…) but it’s look like a big work to do this. You can’t choose another web server than express.

Trails

In Trails you can choose your web server, for now there Hapi or Express4 but more will come like Koa or even a Sails server (if you want to migrate it can be a first step). When you create a new Trails project, you will choose whitch web server you want to use. This will affect the way you write your policies and controllers, if you choose Hapi, you have to write them with the Hapi API, if Express4, then use Express4 API…

3) ORM

Sails

Sails come with Waterline at first, you can change to another ORM, but officially there only Waterline and you have to disable it to be able to use another one.

Trails

Trails support multiple ORM, the first one is Waterline too but it’s not buddle with Trails, if you don’t want it just don’t install it and install the ORM you want to use (Bookshelf for example).

4) Web Socket

Sails

Socket.io is the framework used by Sails, it’s unbedded dirrectly in it. You can use another but have to disable socket.io first.

Trails

Once again Trails doesn’t have an one official web socket framework. You can choose witch one you want or create your own and don’t install the Trails one.

5) Assets manager

Sails

Grunt is used by default to manage assets but you are free to use Gulp or anything.

Trails

Trails doesn’t have an asset manager by default, you have to install Webpack, Gulp or the one you want.

6) Automatic REST API

Sails

Sails call this Blueprints, you can configure them to enable/disable what you don’t want to be generate automatically.

Trails

Trails call this Footprints, you have to install the module to be able to use and configure them.

7) Module/Plugin system

Sails

Sails call his modules hooks they can be under your project or install with npm, with some work you can embed some MVC API in it that will be load/merged in Sails.

Trails

Trails have two systems, the first one is trailpacks, there are loaded from your main.js config file and can embed MVC API and configuration files that will be automaticaly merge with Trails project. They can’t be under your project, they have to be installed with npm.
The second system is microservices, I will not talk about it for now because it’s not define yet 🙂 but take a look at it on github later.

8) JavaScript

Sails

Sails use basic JavaScript ES5, it can run on Node 0.11 and more.

Trails

Trails use ES2015 (ES6), that allow developpers to use classes, const/let declarations and more… (see http://es6-features.org/#Constants), it can run on Node 4.0.0 and more.

Conclusion

Now you know all about the differences between this two MVC Node.js frameworks. You can make your choice and start coding ! 🙂 for now Sails is in v0.12 and Trails is in beta (7).

4 thoughts on “Sails vs Trails

  1. Gadi

    Thanks for your article. I used sails for a small project, but found it missing too many features, so I switched to django. Waterline tries to be too generic, working with both SQL and NoSQL databases. Since I was using SQL, the results was too difficult to use. Joining multiple tables using futures was just too cumbersome. Also, sails may work well with REST, but the included HTML template engine was also difficult to use.

    PS. You should run a spell checker on your post.

    1. jaumard Post author

      Thanks for your feedback ! Never use django 🙂 but yeah Waterline is too generic, the power of Trails is that you can use any ORM you want easily

    1. jaumard Post author

      Yeah sails doesn’t seems to move a lot recently, don’t hesitate to join the Trails Gitter channel ! Docs is small for now but the community try to help we they can 🙂 that’s pretty cool

Leave a Reply

Your email address will not be published. Required fields are marked *