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

Iren Korkishko on June 19, 2018

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... [Read Full]
markdown guide
 

Iren, I love your posts but I have a different opinion with this one.

MVC is old-school. JavaScript is great in so many ways from other languages mostly because of its unopinionated nature and easy-boot capability. Sails brings the old school way of telling users to do things in an opinionated way. There's nothing wrong with that but when your code grows and when you start building custom functionalities by extending the framework it makes it difficult for new mates to understand the code and Google won't help you much either.

JavaScript is so much better when it's not opinionated. When we want to build an opinionated web application, we could rather choose Rails rather than Sails which was built to mimic Rails.

 

As a Rails/JS developer, what I miss in JS is exactly the lack of conventions in the community.

When I start working in a Rails app (if the former developer was competent), I know exactly where to find everything. I know what a class will contain without even needing to open it. And I know the most typical 10 gems like the palm of my hand. Because of that, I can be helpful since the minute one.

And believe me, 99% of web apps are the same. We are not building this snowflake that requieres obscure patterns. We are not solving any problem that nobody solved before.

My feeling is that in the Rails ecosystem there's a lot developers who are building one more web app.

When I work with JS, I sometimes have the feeling that I am entering a jungle with a machete in my hand.

In the JS ecosystem there are excelent developers, but I've seen as well a lot of kids running like a chiken without head, trying the last pattern they found in a Medium article, just to prove themselves that they are more clever than their peers.

Funny thing is that this is not new neither! For many years, the developer Guru, respected by everyone, was the one who wrote the code nobody could understand. Then Code Craftmanship came and introduced sanity and best practices...

But, sadly, it seems that we are going back to the old school.

 

you are free to make yourself slave, if you love it. I prefer to keep my freedom ... my old freedom ;)

For some people, freedom is to be able to choose the amount of pickles in their BigMac. ;)

 

I find you comment interesting. It is exactly when your code grows that you want a pattern like MVC helping you (not always MVC, but yes sometimes). Otherwise what you grow is just spaghetti code with an ad-hoc structure that's only in your head.

Talk about hard for mates to understand the code.

 

Same here.

I knew a few people between 2007 and 2011 who started doing web development with Rails and they came all back screaming, because it was always a pain to get customized features working.

But yeah, if you are into the whole on-premise stuff and don't need too obscure features, you're probably better off using something like Sails.

I personally prefer these Sinatra like frameworks. With the help of npm/yarn you can get highly customized software up and running fast. If I need cloud stuff, I use AWS SAM.

 

Thanks for the comment, Dinesh! That is very interesting and worth consideration opinion. And I think some developers will support you. However, Sails seemed interesting to me. And I also know that some developers use such solutions if they just recently switch to JS from, let's say, Rails.

 

I've heard about AdonisJS, quite similar to Sails ("JS clone of Ruby on Rails"), I've read some reviews about it from people who like it better (usability, performance etc).

However I wonder if this concept (a monolithic MVC app generating HTML pages) still makes much sense in this era of API backends and SPA frontends, especially when you choose JS/nodejs.

Personally I'm now a fan of FeathersJS (feathersjs.com), a much smaller network focused on REST and realtime APIs. It isn't inspired on Rails or MVC but modeled on a "services and hooks" concept (sort of like Express middleware pipelines).

 

Adonis is the best JS framework I've used, and the documentation is very sparse, and I had to lean a lot on the community . That said, it really makes it easy and fun to build web apps.

I've started using Phoenix on Elixir in the past few days, and it has been awesome! It is advertised as Rails/MVC without the compromises. It supports JSON API without HTML first class, and there are some great tutorials on using it with for example Phoenix, Apollo, GraphQL and Vue. The documentation is amazing (tons of examples and thourough. Coming from JS, the language syntax isn't very difficult at all, and from Rails it is even easier. One of the main selling points is 2-4x faster than Node Js depending on clustering, and a whopping 10x faster than Rails or similar python equivalents. It is only beat out by much more low level languages like Java, Go, Rust etc.

I haven't gone too far with Phoenix+Elixir yet, but it seems like it is much better than Node JS for building MVC/structured backends.

 

Great to hear about your experience with both Adonis and Elixir. I think that Elixir (once you get over the hurdle of picking up FP) makes it much easier than node to create robust and scalable apps, concurrency and reliability are built into the underlying platform, with node the burden is largely on the developer, I've experienced that first hand. Easy to crash or lock your app if you make a mistake.

The doubt I have about Elixir is not FP but the popularity of the platform, it's still quite a niche language. But, it has an active and enthusiastic community, great documentation, and the ecosystem around it isn't tiny, most of what you need seems to be there.

I've also briefly looked at Clojure as an FP language but found it quite challenging, also because of the immaturity of the tools etcetera, everything feels quite cryptic with a large learning curve. Maybe ReasonML would be something to look at, like Javascript it can run both on the client and the server which is nice. Yes and Go is becoming popular, and it's very performant obviously.

 

Adonis is the best JS framework I've used, and the documentation is very sparse, and I had to lean a lot on the community . That said, it really makes it easy and fun to build web apps.

I've started using Phoenix on Elixir in the past few days, and it has been awesome! It is advertised as Rails/MVC without the compromises. It supports JSON API without HTML first class, and there are some great tutorials on using it with for example Phoenix, Apollo, GraphQL and Vue. The documentation is amazing (tons of examples and thourough. Coming from JS, the language syntax isn't very difficult at all, and from Rails it is even easier. One of the main selling points is 2-4x faster than Node Js depending on clustering, and a whopping 10x faster than Rails or similar python equivalents. It is only beat out by much more low level languages like Java, Go, Rust etc.

I haven't gone too far with Phoenix+Elixir yet, but it seems like it is much better than Node JS for building MVC/structured backends.

 

Thanks for the comment, Ieob! I'll take a look at both AdonisJS and FeathersJS!

 

Am I crazy or wasn't there a time where Sails.js were one of the top alternatives to Express? I remember looking to pick up Node and found a recommendation to Sails (or at least a similarly themed one - I vaguely remember a boat logo on their website). Or maybe I'm mistaken since they have an Octopus as a mascot now.

 
 

Hi, John! You're not crazy! :) Sails.js was one of the main alternatives to Express. But today I refreshed it for us because Sails.js v.1.0 is out.

 

Am I the only one who's had a bad time with using Sails.js? 😞

Sadly enough I've used it for the last two years to run the back end of an app for my startup. I still regret it. In comparison with Express, it just creates such an unnecessary overhead, with no opportunity to customize things. I hope that's fixed with version 1. 😊

 

Thanks for the comment, Adnan! I hope such things you've mentioned about Sails is already in past with the new version. However, different projects and different developers will rarely agree on what is the best and the most convenient solution. So Express or Sails (or Loopback, or Trails) it always depends on your comfort with some features and approaches. And there is no silver bullet, unfortunately :)

 

Ahh The love for sails <3 Who wouldn't love sails?
Sails has been my defacto Node backend framework for almost two years, and I can tell you that I have been loving it every day, it's just so easy to use it, maintain it the only things I have had issues is with migrations and sql complex queries but, if you add something like knex to help in those cases, you are more than covered! awesome post! I do even have some dated posts on how to do stuff in sails in my website

Cheers!

 

Thanks, Angel! Nice to hear about your experience of working with Sails!

 

Iren, thanks for the post. I'm curious on your thoughts on sails.js vs. Strongloop's Loopback.

I recently did a side project for a friend and decided to go with Loopback instead of sails, mainly because I felt it was more up to date than sails. For example, Loopback 4 has first class support for Typescript coming in Loopback 4. cc: @ybaruchel

 

Thanks for the comment, Nick! That is interesting, and I need more time to compare them both. But talking about TS support, Sails.js v.1.0 provide it. Although the details have to be considered. I think I will come up with the comparison next week!
Thanks again!

 

Thanks for this write-up! @iamkael mentioned Sails.js (and not liking its documentation) recently, but I didn't quite get what its intended use case was from the website. Now I get it, especially the appeal to Rails developers!

 
 

I've seen Sails before, but I think I saw Trails first.

Have you heard of/used Trails? It seems pretty comparable at first glance but I wanted to guage your opinion on both.

 

Thank you for the comment, Jake!
No, I haven't meet Trails before. But it seems to me that Sails and Trails are aimed to solve the same tasks. And they similar because they both are built on Node.js. But at a first glance, the main differences lie in convention over configuration approach used in Sails. This part makes Sails.js very easy to use with Rails developers. But, of course, I need more time to compare them both. And I think it will be another article for that!
Thank you for mentioning Trails!

 

"Trails is built and maintained by former members of the Sails.js core team, and offers an upgrade path from existing Sails applications, but it utilizes exactly zero lines of code from the original Sails project."

I read some stuff on different GitHub repos. Seemingly many people weren't happy with Sails' development progress, so Trails was started.

That is very interesting! Thanks, K! Further exploration of this topic is needed!

 
 

Cool post, very clear, very detailed.

Question, I'm seeing the package.json of sails in github and the tag 1.0.0 and it says

"express": "4.16.2"

Are you sure that it still uses Express v3 ?

 

Thanks for the comment, Casiva! Here sailsjs.com/documentation/upgradin... it is said that session middleware that was designed specifically for Express 3 (e.g. very old versions of connect-redis or connect-mongo) will no longer work, so you’ll need to upgrade to more recent versions.

 

Was very keen to try Sails until I read this "development is very slow" :(

 

Thanks for the comment, Tu!
It's nice that creators are honest to mention the main Sails drawbacks. But it's not obvious that you will experience slow in development. Anyway, to know good it or not you should try it first.

 
 

Thanks for the comment, Alex! Indeed, Sails v1.0 is out, and that was one of the main reasons for me to write about Sales.js today!

code of conduct - report abuse