📜 ⬆️ ⬇️

Node.js is not suitable for typical web projects



"Node.js is not suitable for serious sites and web applications, but only for writing small APIs."
This is bull * hit. I have to say it.

From the translator: An interesting article from Ionut-Cristian Florescu has recently appeared on coderwall.com about using Node.js for creating ordinary (“typical”) web projects. Before reading it, I completely agreed with the title of the article, but now my opinion has changed somewhat. The position of the author can be controversial in many points, but his arguments are quite interesting. If you have your own opinion about this, leave it in the comments.

I have heard these words so many times that they already bored me to death. They mainly come from people who have never used Node.js for anything other than playing the basic todo-tutorial, from “pseudo-developers” or “smart guys” who like to read about what is now in trend, but have not developed nothing serious.
')
But besides them, there is a brave new world, where they seem to think otherwise. Guys like Klout , Geeklist , Transloadit , Cloud9 , and many others featured on this page .

Are they all wrong?
But still, where did this unfounded myth come from?

Outdated data


First of all, despite the rapid pace of implementation, Node.js is still a young technology. It is no longer immature, but it still develops quickly, quickly enough, so that the marketing hype and technical articles on Node.js do not keep up with it. In fact, most of the articles and topics on the forums devoted to discussing what Node.js is good for and why not are very outdated.

Pagans against the infidels


Secondly, web development and programming languages ​​are almost always objects of religious worship, and many people in these areas do not consider JavaScript to be the "real" programming language. Well, perhaps it’s not perfect, but good enough to be the most common language on the Internet at the moment.

"Callback hell"


Most Node.js developers should be aware that due to event-oriented nature, it’s quite difficult to do things on Node.js that require consistent execution. In my opinion, this is probably the biggest weakness and at the same time the greatest strength of Node.js. Strong, because if you know your tool, it lays the foundation for handling an incredible amount of simultaneous connections, perhaps an order of magnitude more than you could get using PHP, .NET, or RoR. Weakness, because most people rightly seek to get rid of such code:



Each background operation returns its result (or error) in the callback. The positive side of this is that your application server is not blocked while waiting for the operation to complete, but at that time it can perform other actions, such as servicing another request, which keeps your application fast and users happy. The downside is that if you have a lot of background operations (for example, to access any data), your code becomes ugly and incomprehensible.

The good news is that there are quite a few very elegant ways to smooth out this problem: Async.js is probably the best known, but if you use CoffeeScript you should definitely consider the next step to “simple and powerful optimization of asynchronous flow control” with IcedCoffeeScript . I did not pay him much attention when I first turned to Node.js some time ago, but now, after using it in several projects, I can really imagine the code without await and defer. I consider this the ideal solution for most common usage scenarios, where you have either a series of sequential operations, or a combination of sequential and parallel tasks:



Node.js ecosystem lacks a framework like Rails


Leaving behind the problems of language / platform, I will say that this is also a false myth. I personally love Ruby and Rails, but I find them somewhat redundant for small and medium-sized web projects, and I like being the real master of my code. I prefer to start with a small, manageable code base and expand it, add modules if I need them and when I need them. Therefore, I believe that Express.js provides the perfect balance between lightness and extensibility. And Connect , (on which Express is built) provides you with all the features of Rack, with I dare say, even a richer ecosystem. I know that most people will compare Express to Sinatra, but I think Express is more than that, and I also heard that even hardcore rubists admit that Rails is too redundant at times.

But if you use Node.js and you like Rails, maybe you should pay attention to Tower.js or Geddy .

Packages, Manage Connected Files


Of course, in the world of Node.js there is nothing comparable with Sprockets ? Actually there is. And not one. Node.js is the place where such things appear. Bower , Brewer.js , Piler — these are just some of them.
Mihai Bazon 's UglifyJS also works on Node.js.
Trevor Burnham, author of CoffeeScript: Accelerated JavaScript Development, wrote connect-assets , which is now supported by Andrew Dunkman .
For developers who need a simple but equally powerful alternative, I posted ASPA and ASPA-Express a few months ago in open-source.
Thus, there is plenty to choose from.
How are things with template engines? They are also enough , the best in my opinion Jade and Stylus .

Speed ​​and concurrency is not everything


No, speed and concurrency are not all, but they are damn important. I heard that many people say: “I’ll use PHP / .NET / Ruby for now, and if my site’s traffic reaches thousands of visitors per day, I’ll simply increase the number of servers.”

But apparently this is easier said than done. Even GitHub sometimes has problems - I am sure that many times from time to time I saw an annoying page with an unicorn error.

And no one can guarantee that you will have a lot of money before you get thousands of visitors to your site. This usually happens in reverse order, if at all.

Also, I used to hear about sites that Google search robots simply “put”. And of course you do not want this to happen to you, because at the moment in the online business, if Google is not “your friend,” then you simply do not exist.

Thus, the ability to handle large volumes of traffic without losing the speed of the site will never be superfluous. Especially if you do not have to pay large sums for infrastructure and support (no one will write it on pure C).

Lack of good Node.js developers


Since Node.js is based on JavaScript, it has attracted many web developers with “a lack of proper experience in server development” (that is, people who are not even familiar with the basic design patterns). Although this is true to some extent, I think that most beginners will still stay away from Node.js.

In addition, the same applies to any other platform, framework or language. There are many developers, but there are far fewer good developers. In addition, in most cases, a good share of common sense will compensate for the lack of perfection.

Large corporations do not use Node.js yet


Fine. Large corporations use .NET and J2EE, at least in my world. If you want to be there, stick to .NET and J2EE, attend Microsoft and Oracle seminars regularly, and maybe even consider Scala .

This is just my opinion. It is not immutable, but at least I can say that it is justified; Throughout my career I have written code in C #, Java, PHP, Ruby, JavaScript and more. I worked on "serious" business applications and I also managed to survive as a private entrepreneur not in the field of information technology, so I learned to look at the world not through the prism of IT. But the coding process was definitely more fun when I discovered Node.js.

Based on all this, I had no doubts when choosing Node.js, when I re- tweaked LeasingSH.ro , a car sales site known in Romania. This is not a big project, but this is the very typical web project we are talking about:



One of the advantages of using Node.js is that we can probably handle more traffic than we ever get. In addition, the response time has noticeably decreased, despite the fact that we still use a single web server:



The code also became more readable and supported, since the use of new technology indirectly introduces new features (as opposed to the old PHP), such as using BitBucket to manage source code, a clearer division of tasks - mainly due to the use of Jade templates, efficient compression and management of connected files with ASPA .

And in conclusion, I would like to see more typical web projects executed on Node.js. Too many of them are still implemented in PHP. Don't get me wrong, I've used PHP for several years and I don't mind it, but sometimes we need to look to the future.

Source: https://habr.com/ru/post/191646/


All Articles