Express and Sails? Which is better (Part 1)

Hello everyone , today I will introduce to you two quite popular frameworks of Nodejs : Express and Sails . Which one is better, which one should be?

Express

This guy is too classic, if you have found out about Nodejs, you would have heard it before Express . This guy is a node's framework that makes it easy to build a Restful server, or like a web application (I don't know how to explain it later, but I understand that building something like WordPress, do you try the code)

Express

Fast, unopinionated, minimalist web framework for Node.js

In other words, this guy is like the team of other frameworks including Sails that I mentioned in the headline.

Some build frameworks are based on Express

  • Feathers : Build prototypes in real minutes and production ready-time apps in days.
  • ItemsAPI : Search backend for web and mobile applications built on Express and Elasticsearch.
  • KeystoneJS : Website and API Application Framework / CMS with an auto-generated React.js Admin UI.
  • Kraken : Secure and scalable layer that extends Express by cung cấp cấu hình và Convention.
  • LEAN-STACK : The Pure JavaScript Stack.
  • LoopBack : Highly-extensible, open-source Node.js framework for quickly creating dynamic end-to-end REST APIs.
  • MEAN : Opinion of fullstack JavaScript framework that simplifies and accelerates web application development.
  • Sails : MVC framework for Node.js for building practical, production-ready apps.

Home http://expressjs.com

sails

What Is Sails.js?

Không thể làm việc để tạo Custom, Enterprise-grade Node.js apps. Hành động này để tạo bản đầy đủ mẫu MVC của cấu hình như Ruby trên Rails, nhưng với hỗ trợ của modern apps: data-driven APIs with a scalable, service-oriented architecture. It's especially good for building chat, realtime dashboards, or multiplayer games; nhưng bạn có thể sử dụng nó cho máy phục vụ application – top to bottom

As mentioned above, this guy is built according to Express. Mean

Sails = Express + add a new function department + add new organization file = Framework

So don't use her grandmother Sails for now, just as handsome as Express and richer again (marshal)

Home http://sailsjs.org

Here I will compare some of these guys' ability to work so that you can imagine which guy to use.

RESTful server

RESTful

REST defines architectural rules for you to design Web services that focus on system resources, including how the resource states are formatted and delivered over HTTP through a large number of users and written in different languages. I copy it online, it's hard to understand vl you don't read it

In my opinion, it is simply that it regulates the status and definition of an API server. For example, when you get information, use the GET method , create a new POST , edit it as PUT and delete it as DELETE . The sent result is usually JSON . Whatever it is, it wants to be nothing

For Express , if you want to build a RESTful server, you usually do the following steps.

  1. Design model (usually sieu mongoose )
  2. Write each controller if demand is complex, or I will drop it into app.js
  3. Require the above items into app.js
  4. Install some middleware, connect to mongodb
  5. app.js node
  6. Lỗi

Looks pretty tired, guys

If Sails is much easier

  1. sails generate api flash
  2. Accomplished

With the function called "Blueprints", it makes the remaining work extremely easy, Sails also supports saving data as file right at the beginning of setup so you are not tired to establish a connection with db server, if any, is faster than express . Guaranteed

However, I prefer Express and recommend that you use Express with me. Crazy, obviously Sails is much better, quickly like what Uncle Bill-san said.

I choose lazy people to do difficult things. Because a lazy person will find an easy way to do it

Bill Gate – San

The difference is here, guys.

Doctors run the app.js node with Express and sails lift with Sails to try.

Express launch faster! Simply because Express is an extremely lightweight framework, what functions do you like to have on your own and add it while Sails has too many functions that you have not used yet, it makes sails become heavy. And I often have the habit of fixing some three characters , Ctrl + S , app.js , F5 , still error , go back to the beginning . So even though the difference is not too big, it makes me feel uncomfortable. But building on Express is very annoying, up to 6 steps. It really looks big, it's really fast.

Design model ( ./model/User.js )

Write controller ( ./controllers/user.js )

Long stars. Actually, it is only longer than Sails in 4-5 line model. No sails generate api flash is running, trust vl. Actually running, but applying to reality, you have to fix from model to controller accordingly.

So you can see when writing in Express , you are only longer than Sails

  • 4-5 lines in Model
  • 4-5 lines to require Model and Controller to enter app.js
  • 10-15 lines add middlewarve, db connection, http server setup

In total, 25 lines, you can save the app.js file to save it, as your own framework, upload it to Github and be famous. Later, only 4-5 lines were revised to apply to another project, right? Having its own framework, it just runs fast. So if you build a RESTful server, you should use Express like me.

ITZone via cuthanh

Share the news now