Hello to the whole community! My name is Bruno, and I've been in DesdeLinux as a user. It's time for me to make my first posts in this community 🙂
Today I bring you a guide on NodeJS y sails.js
Node.js
It is a programming environment, based on the language javascript with an event-oriented architecture, ideal for asynchronous programming. Node, is based on the engine V8 of Google.
It maintains an active open source community, who have written many modules to facilitate our development.
One is socket.io (Allows the server to send real-time updates to the client, for example a GPS tracking)
What is?
Node is designed for situations where the traffic is too large, causing server logic and throughput not necessarily higher. And not only that, but in real time and with great scalability!
Why Node?
1) It is open source.
2) If you ever thought of using a single language on both server and client side, here's the solution.
3) Scalability and Concurrence.
4) etc
sails.js
What is Sails?
It's a MVC framework that mimics the model of ruby on rails (Yes, you heard correctly: D) for the creation of small or large applications quickly, easily and safely. further has support for modern application requirements. It doesn't matter which database you use, Sails provides a layer of abstraction, which makes the choice of it indifferent. Sails has:
- The ability to create RESTful JSON API automatically.
- It has incorporated the module socket.io.
- Generate routes automatic for your controllers.
- Provides system of authentication of users and access control role-based.
- Grunt as Task Runner (Automatic tasks such as minification, compilation, testing, etc)
- Assets: All files in their corresponding directories (css, js) are unified in a single file and minified, to reduce considerably page load and limited number of browser requests.
Installation of Node.Js
sudo apt-get install python-software-properties python g++ make
sudo add-apt-repository ppa:chris-lea/node.js
sudo apt-get update
sudo apt-get install nodejs
Sails.Js installation
Latest stable version:
sudo npm -g install sails
Create the directory skeleton:
sails new testProject
We enter our Project:
cd testProject
We start the server:
sails lift
Yeeeeeeeeeeah! we entered http://localhost:1337/
FIRE:
- Drivers
- Adapters
- Models
- Policies
- Services
ASSETS:
- images
- js
- styles
favicon
robots
SETTINGS:
- local
404.js, 500.js… ..
routes.js
session.js
sockets.js …… ..
NODE_MODULES:
- ejs (template engine)
- grunt
- optimist
- sails-disk
VIEWS:
- Home (here is the root template, localhost)
- 404.ejs
- 500.ejs
- layout.ejs (For those who used rails, layouts.ejs behaves same than layouts.html. *)
END
So far my knowledge, and I hope I have been of help to many ... I am new in this technology so any constructive criticism is welcome : )
This post arose to do it, because I am developing a kind of psychosocial network (Nothing from another world). With purposes of learning, and few resources. the idea is to also make a home server that supports it (Surely make a tutorial of it) As I said before, the resources are few, so the optimization It's very important. (and even if they weren't too ^^)
I'm amazed at how faithful it emulates RoR, although many hate RoR for its poor performance (without configuring) trendsetting code cleaning.
The subject is very interesting, I hope you continue to develop it, congratulations.
I don't hate RoR, the truth is that ruby's philosophy of "there are many ways to do the same thing" is usually a problem because not all of them are really the most efficient and when you want to answer a question, in many cases you have that Little problem in which everyone responds with a different way of doing the same and you tend to get more confused D:
Regarding this framework for Node, as it is not for huge or large things, Node is used together with other frames such as Django for specific things, I think the example of Mejorando.la is like this, they build the whole site and manage its bases of data with Django but the realtime issues are left to Node, though I'm not sure so I can't talk too much about that.
I think that's how you say, they use Django for the base of the site and Node for things in real time ... Well at least that's what I always hear freddy vega say
NodeJS is not like Django or PHP, or ruby. But it is a server such as Apache, Nginx, etc.
Sails is the framework that makes use of nodejs and express (another framework) together with some modules such as socket.io, for the creation of web applications.
Regards!
so if you want to include a chat made with nodejs with a page in python with Django (to continue with the example of improving.la), you would have to use a frame, or assign to apache (if that is the case, I have no idea which server use python) the path http://miweb.com ya node.js http://miweb.com/chat and communicate them
Hey that super interesting….
What I did not finish is why is Node JS used for the web?
it is an alternative to apache, with the advantage of being in real time (applications that are communicating all the time and not only when the request is made).
NodeJS is not an alternative (or replacement) to Apache, NGINX or any other web server. NodeJS is a JavaScript interpreter for the server, allowing you to create applications with this language that would otherwise require the use of languages such as Java, Python, Ruby or PHP.
Yes, maybe I expressed myself wrong. What I wanted to convey is that node.js runs its own server and does not need 3rd parties to work (apache, nginx, cherokee, etc)
Regards!
very good, I hope more tutorials to be able to follow node.js and do something in real time
Here is a 200-page book, with an introduction to Node.js through Koans. It has an into to Node.js, and the "resolution" of a part of a problem posed (the example is twitter) with Express as the header framework… ..
http://nodejskoans.com/
PS: Sails is made on an Express basis, usually most of them are.
Regards!
Excellent contribution Bruno .. Welcome 😀
Thanks to you and the whole community for letting be part of it 🙂 Greetings!
Very interesting Bruno 🙂
Thank you!
Excellent article. Thanks a lot.
I currently use sails in some of my projects. I would like to ask you where I can get more information about the role-based access control of sails, if possible in Spanish, but if not, in English. I would like to add access control to one of my pages but I want to establish permissions for some users from a certain route and others from another route. Is that possible with sails? I can't find much information about it.
Thanks and congratulations for the article.
All the best
Elvira.
Hello Elvira!
Regarding what you mention, be it Sailsjs or any other framework, what you propose is related to the modeling of the data and the restrictions that the system imposes.
You could create something like "groups" (roles) with different permissions and associate each user to one of them.
Particularly in sails they are called "policies" and you can see it here: http://sailsjs.org/#/documentation/concepts/Policies
Greetings and thanks for your comment!
Thank you very much Bruno. With your prompts, I found an elegant solution. a greeting