Apologies in advance for any trodden toes.
Apologies in advance for any trodden toes.
Advantages of node.js as I see them:
- Provides npm (a state-of-the-art package manager which introduced a number of innovations)
- Built on V8, which is possibly the best dynamic language compiler made to date, in terms of performance
- Provides a well-done streaming I/O and event model, which many languages fail at
- Provides an extremely powerful and high performance async/concurrency model, which is set to improve as promises and other concurrency patterns mature
- Has a well-tested, high-performance, properly layered standard library (most of the time)
- Has a nice C++ extension framework
- Has a very active (though sometimes rough around the edges) developer community
The downsides are:
- It's Javascript, which has some serious design issues as a language
- Currently still suffers from callback spaghetti, which is set to improve as per point 4 above
- Can be very hard to debug in the face of its async model because of insufficient built-in debug facilities
I've used both Python and Javascript for years, and the more I use Javascript the more I realize how ad hoc Python really is. So many of it's features (metaclasses, raising an exception to break iteration, the MRO, the import behavior, etc.) seem to be hacky solutions to problems of it's own making. Javascript is a much smaller, and therefore simpler language.
What's wrong with raising exceptions to break iteration or with the import behavior?
You don't have to.
def mygen():
yield 1
yield 2
return
print "never been here"
>>> list(mygen())
[1, 2]
I agree some parts of python are hackish though. Maybe because of legacy reasons. And py3k didn't fix all of them1. npm is extremely easy to use and has a lot of traction. Language X is going to be a tough sell if it lacks good libraries.
2. node.js devs tend to be religiously adherent to the idea of small modules. While not everyone like this, and some would prefer large frameworks, it is definitely a more flexible model.
3. Speed. I happen to write mapping and geospatial analysis software. Most of the existing solutions are python based. I spent months optimizing one particular algorithm in python and was able to get processing time down to 70 seconds. This was not acceptable for a web app, so I wrote a new geostatistical engine from scratch in node.js. New operating time: 35ms. Sure, there were probably ways to optimize the python code further, but it was never going to touch the node implementation.
https://github.com/morganherlocker/turf
4. In data analysis type applications like this, async IO is a huge help. More connections with less servers means huge cost savings.
5. Syntax is just syntax. When I was a python dev I would look at javascript and cringe, now I find myself doing the reverse. I fully expect to look back at both and cringe when I am a few years into my next language. We all experience that feeling when we see something different than we are used to.
Also the whole streaming/evented approach to web development is really cool. I know it's nothing new, but being able to require() a few modules and write a file upload component in 10 lines is pretty nifty.
- If you're building a web app (perhaps a single page web app), it might be useful that you can share client side code and server side code. Take input validation as an example -- you can use the same `validateEmailAddress` function on the server and on the client -- guaranteed to be consistent.
- Javascript is a fascinating language.
- Maybe others can contribute some performance numbers? My impression is that V8 is very fast -- can JS outperform other scripting languages?
- The whole Node.js approach to concurrency is very different than using threads -- it's fascinating, as well.
It's also javascript, (which has some really nice properties, and a few bad ones) and ubiquitous in web development already.
The real reason for it's popularity is that a lot of the ruby guys seemed to have jumped to Node.js :)
I think it's because a lot of front-end developers jumped to Node.
[1] https://github.com/TechEmpower/FrameworkBenchmarks/tree/mast...
It was never designed to replace rails or django in what they do best : classic web apps with a lot of static pages served from server-side templates.
So if you are designing an online news paper, a blog or e-shop ,you shouldnt be using it.
However,you might want to send 100000 mails to your customers each week. Node can help you with that.You might want to fetch loads of data from a 3rd party api, Node can help you with that, or add real time functionalities... Node can be a component of your setup(like a RDBMS,a proxy,...),it doesnt have to be the core.
The real issue is not Node,it's all the craze around it that makes people give up solutions that work for the new hotness,so you get people trying to port rails or django to node, which is stupid.
So please dont bash Node because of the way some people try to sell it to everybody for everything. These people will go away soon and jump in the next bandwagon,but NodeJS is here to stay.
"Evented, async, processing is faster than threads in many cases. What if you had a platform/language that you could only do async IO in? Well we could take an existing language and replace the IO layer, or we could just take javascript that has no-IO layer and add it in. Thus in node it's impossible to write blocking code. (Let me knoe if I'm wrong on that last bit)."
Then it went from interesting experiment to useful, and thus to popular very quickly. Either because V8 is so very fast, or because lots of people know and like javascript, or because callbacks are not that bad :-). Not sure which.