From the translator: I am just starting to look closely at Node.js, and, having discovered this guide, I greatly regretted that it had not caught my eye earlier. I hope that this translation will help many to figure out what a Node is and what it is eaten with.You are already scratching your arms to try Node.js and is it time to start processing your bosses? Do not hurry! For some companies that I
advised on whether Node.js was right for them, the correct answer was “No!”
This guide is a set of tips based on my personal experience for those who want to find out if it makes sense to use Node in their company, and, if so, how to convince the authorities.
')
Bad options
Heavy calculations
Although I love Node.js, there are several cases where its use is meaningless. The most obvious of these are applications with lengthy complex calculations and a small number of I / O operations. So if you are going to write a video transcoder, artificial intelligence or some other digital crusher, please do not use Node.js. This is basically possible, but it is better to write in C / C ++.
On the other hand, node.js makes it easy to write add-ons in C ++, so you can, of course, use it as a script engine on top of your top-secret algorithms.
Simple CRUD / HTML Applications
Although Node.js may eventually become a cool tool for any type of web application, so far you shouldn't hope that it will give you more advantages than PHP, Ruby or Python. Yes, your application may turn out to be slightly better scalable, but just being able to handle a large flow of traffic does not mean that this flow will suddenly increase only from the fact that you used Node.
Despite the fact that now there are quite good frameworks for Node, there is still nothing close to Rails, CakePHP or Django. If your application is mainly engaged in filling HTML templates with data from the database, Node.js will not give you any tangible benefits yet.
NoSQL + Node.js + Any fashionable garbage
If the architecture of your future application resembles a collection of recipes from the “NoSQL Kitchens” series, exhale, pause, and read the next paragraph.
Yes, Redis, CouchDB, Cassandra, MongoDB, Riak and so on look very appetizing. Something like an apple that Eve was seduced with. You are already risking using Node.js, and you should not exacerbate this risk with another new technology that you most likely haven’t figure out until the end.
Of course, you can find a lot of arguments in favor of document-oriented databases, but if your application should be profitable, the reliability of using proven technologies (Postgres or MySQL) should be more important for you than being able to raise your geeky CSW and brag to friends.
Good options
JSON API
Node.js brilliantly copes with building lightweight REST / JSON interfaces.
Non-blocking I / O and JavaScript make Node a great option for writing wrappers around a database or web service that communicates with a client in JSON format.
Single Page Applications
If you are writing a complex AJAX application like Gmail, Node is also very good. For modern web applications that do most of the work in the browser, the server is great, which can simultaneously handle thousands of requests and has a low response time. The ability to reuse the same code, such as validation, on the server and client is also a plus.
Using command line tools
While Node.js is still very young, there is a temptation to write everything you need for it especially for him. But it may be much more beneficial to use a huge selection of existing command line tools. Node is able to generate thousands of child processes and work with their output data streams, which can give serious advantages to those who do not want to reinvent bicycles.
Stream processing
Traditional web application stacks typically treat HTTP requests and responses as atomic events. But in reality these are streams, and Node.js applications can take advantage of this fact. Excellent examples are
file handling during upload to the server or data transfer between different layers.
Soft real time systems
Another great feature of Node.js is the ease with which soft real-time systems can be created. I mean things like Twitter, chat, sports betting, or IM protocol interfaces.
Just be careful! This is JavaScript, and the response time can vary greatly if the garbage collector (which, alas, blocks the JavaScript execution flow) suddenly enters. So don't try to build a hard real-time system with a guaranteed response time on a Node. Erlang is much better suited for this.
How to convince the authorities?
Now, if you are sure that Node.js is right for you, it's time to convince the bosses to try.
Make a prototype
The best way to launch an offensive is to propose to sketch out a prototype of the system or its part in a week. Usually, the boss easily agrees, as this does not oblige him to anything.
And when you have a working prototype on your hands and test results, these are already much more convincing arguments in favor of Node.js.
Where to get the developers?
Whatever you think about JavaScript, it becomes a universal, uniform web programming language. One or more JavaScript interpreters exist on almost every computer in the browsers and any web developer almost certainly knows JavaScript at least a little.
This means a huge choice of programmers for every taste and color in the labor market, and you probably already have the necessary personnel in your company. So if you work in a growing company that is actively hiring, this is another argument in favor of Node.js.
Active community
The Node.js community is now growing at a breakneck pace, attracting the best developers in the industry. This means that the Node ecosystem is also growing, it is getting easier to get support for free or on a commercial basis.
Performance
This argument is best not to force, but if performance is critical for your application, then Node.js has something to offer. Google’s underlying Node V8 engine is already very fast, and it is getting better every day, because now all five major players in the browser market (Mozilla, Google, Apple, Microsoft and Opera) are trying to create a JavaScript engine better than its competitors.
If we also take into account the non-blocking model of input-output Node, then you will have to try to write a braked application. Most Node applications can easily handle thousands of simultaneous connections on completely ordinary hardware.
Support for large corporations
One of the risks in using the young Open Source project is the lack of long-term guarantees from the authors. But this is not a problem for Node.js.
Joyent hired Ryan Dahl and several other key Node developers to sponsor the project, so now the future of Node.js is guaranteed by serious economic power.
Largely due to this, companies like Yahoo! and HP have already decided to use Node in their new products, so you can give your boss more confidence by giving them an example.
How to convince a client?
If you are a freelancer or work in a small company that makes websites to order, then you need to act a little differently, convincing customers. After all, they are very dependent on your decisions and hope that you will support the application you have written.
My advice is to be more conservative, it’s better to double check whether Node really suits them. If so, make sure you have enough time and resources to support. New versions of Node come out often, and it is worth considering the need to update every 3-6 months.
Twitter and blog avtra.