
I don't understand why anyone would use Node.js - zinxq
I don't mean to troll. It's rather an honest question. My thought is based on some assumptions of course, so feel free to launch an attack starting there.<p>1 - Javascript is not fundamentally easier to code in than Java. I wouldn't make that statement with Ruby for example, but I've done lots of all 3.<p>2 - when writing servers, you actually care about performance.  Nodejs is fine, but there are (including Java) solutions that hands down beat it by several factors. And that's on a single or (shudder) multiple cores.<p>The coding paradigm of node.js is not novel, it lives in Netty (among other places).  The reports of having 100k connections is great but again, any server in C or Java written correctly should be able to do the same thing (asynchronous I/O with proper VM/kernel tuning).<p>I am a big fan of trading performance for programming productivity when appropriate. That's the entire point of things like Rails. But developers enter those at the application layer with strong intent of scaling to handle load "if they get popular" with the trade-off of faster development.<p>But if you are writing at the node.js layer, you're writing a server. The V8 js engine changed everything and even made this possible, but dynamic languages are at an inherent disadvantage to statically-typed languages in terms of performance (node.js vs other solutions, and JS vs. Java benchmarks are easy to find)<p>Choosing node.js over netty (again, for example) simply seems like a choice of "cool factor" over performance. Unlike comparing Rails vs. Java for a web app (where I, if able, would choose the former) the coding productivity claims are dubious.
======
Terretta
Your first point seems to indicate you are, in fact, trolling:

> _Javascript is not fundamentally easier to code in than Java._

You provide nothing to support this assertion which wildly contradicts the
accepted conventional wisdom[1,2].

1\.
[http://www.htmlgoodies.com/beyond/javascript/article.php/347...](http://www.htmlgoodies.com/beyond/javascript/article.php/3470971/Java-
vs-JavaScript.htm)

"JavaScript contains a much smaller and simpler set of commands than does
Java. It is easier for the average weekend warrior to understand. ...
JavaScript's main benefit is that it can be understood by the common human.
... JavaScript is a little more forgiving than Java. It allows more freedom in
the creation of objects. Java is very rigid and requires all items to be
denoted and spelled out."

2\. <http://sislands.com/coin70/week1/javajs.htm>

"Java, due to its complex syntax, rules, and restrictions, may seem daunting
for those without programming experience. JavaScript, on the other hand, is
easy to use and learn. You can create sophisticated applications just by just
learning some commands, syntax rules, and the object model of the browser."

Aside from that, if you truly don't understand why _anyone_ would choose
node.js, that sounds like a failure of imagination.

~~~
3am
An 'average weekend warrior' or people 'without programming experience' who
are daunted by the complexity of Java should not be implementing server
applications (see PSN security issues). They are complicated independent of
the language, and anyone capable of implementing one will not be tripped up by
syntax.

The authors points were all legitimate, there was no trolling there. I think a
lot of us have quietly wondered why there was a need for a Javascript based
server framework; maybe a lot of the hype was driven by frustrated/advanced
front-end developers that wanted to work w/ familiar tools combined with the
new/shiny factor. It doesn't seem exceptional in any respect outside of being
implemented in JS right now.

That said, you should be happy for this kind of post. It means that node.js is
catching on enough that it's getting critical attention. Same thing happened
to Rails, and to Java before that.

~~~
crcastle
"An 'average weekend warrior' or people 'without programming experience' who
are daunted by the complexity of Java should not be implementing server
applications (see PSN security issues)"

Disagree. If well-trained professional programmers were the only people
implementing server applications, we wouldn't be where we are today. The fact
that people can tinker, teach themselves, put together a highly-insecure
server just to share their implementation with others provides a huge benefit
to all programmers and the industry in general. Thus trolling.

And again, "I don't understand why anyone would use node.js" is link bait
trolling. Anyone means anyone. I bet if the OP really thought long and hard
(or just for 10 seconds) he/she could come up with at least a reason _one_
person would use node.js. Coming up with one person makes the OP's title a
false statement.

~~~
3am
You are coming up with a blanket judgement based on a small subset of a post
(and in my opinion, not interpreting it as the poster intended). It read to me
like he was talking about production usage, not tinkering. Node.js is slower
and more resource intensive than Erlang (if you're comparing just
async/message passing models), less productive for _most_ programmers than RoR
or PHP, not as battle tested (security/stability) as Java, and fewer 3rd party
libraries than most.

I don't even know about the state of development tools like debuggers and
profilers. My understanding is that Node.js still has stability issues (memory
leaks or GC bugs?) and doesn't utilize multi-core machines very well, either.

I'm all for tinkering, and I expect Node.js to be very successful and as an
additional benefit to improve the V8 engine. But you're being overly sensitive
to call this mild critique (albeit with a bad title) trolling.

~~~
crcastle
Yeah, I agree that I got a bit worked up in my response and my language was a
bit stronger than it needed to be. I guess it was driven a bit by:

a) nodejs is resulting in a _ton_ of interesting projects. whether it is the
best design decision to use nodejs in these projects instead of something else
is another question. the creativity nodejs has helped spark is awesome in
itself.

b) if the OP was referring to creating battle-tested server applications,
he/she should have made that clearer. yes nodejs is immature and crashes left
and right.

c) OP titles like this one (i.e. generalized statement the OP knows to not be
true) do not foster productive discourse and community

------
samdk
1\. I think you're wrong. I would agree that JavaScript's syntax is not great,
but it's still better than Java's. (And dynamic typing, whatever your
complaints with it, does significantly reduce how verbose the language is.)
Also, first-class functions are a _huge_ benefit for me.

Also a lot of JS's syntactical issues/verbosity can be alleviated with
libraries like Underscore. Start using CoffeeScript and you're miles ahead of
Java in terms of syntax and verbosity, and you make some of JS's more annoying
issues a lot easier to avoid.

2\. Yes, you do care about performance, to a certain point. If everything I
was doing had to immediately be available at Google scale, then yes, I'd
consider Java a lot more seriously. However, most of the stuff I do doesn't
have to scale to millions of simultaneous connections on just a handful of
servers. Absolute performance is not my highest consideration, and NodeJS
absolutely is more productive for me than Java.

I think you're missing a couple of very important points, which are why I
think NodeJS is the best tool for some tasks.

First, and by far most importantly, it has Socket.IO, which is by far the best
choice library when you're doing anything in real time. It is fantastic, and
is a huge part of the reason why I use NodeJS for certain classes of
applications.

Second, there _is_ value to being able to share code between the server and
the client for nontrivial web applications. Most code doesn't get shared, but
not having to have separately maintained models for the server and client is
really helpful.

For me, the 'cool factor' doesn't come into it at all. I enjoy programming in
JS and even moreso in CoffeeScript. I dislike programming in Java. And when
I'm not doing something that has to be hugely scalable, Java's only real
advantage is raw speed, and NodeJS has vastly superior tools for doing what
I'm trying to do (real-time webapps), NodeJS is the clear choice.

~~~
gkatsev
I think the main strength is the fact that you are writing JavaScript both on
the client side and the server side. You don't have to mentally switch
languages or anything. Even though people don't think that it has an effect,
it does. And while, even in JS, you'll write things slightly differently when
doing client/server side work but it still would take less brain power than
changing client/server paradigms as well as changing languages.

------
TrevorBurnham
I'm the author of the CoffeeScript book from PragProg, which includes a
chapter on Node.js.

I've done a fair amount of server-side development in Java and Ruby. What I
like most about Node.js is the feeling that you can be as close to the metal
as you like. You don't have the endless boilerplate of every Java web
framework, or the extensive "magic" of RoR. With Node and a framework like
Express, you can understand things at the level of "let me look at this HTTP
request and decide how to respond to it." This, to me, is beautiful:

    
    
        app = require('express').createServer()
    
        app.get '/', (req, res) ->
          res.send 'hello world'
    
        app.listen 3000
    

It's going to take more time to build a full-featured web app that way than
with RoR or Django, but you'll understand it better and it'll scale well. For
something that's only been around for two years, Node.js has a remarkable
ecosystem—you can tell that a lot of very smart people are gravitating to it.

And yes, being able to use the same language for both your client-side and
server-side code is pretty dang cool. It's also practical. Historically,
development teams have tended to focus on the server-side and learn JS only
well enough to hack together some jQuery into doing what they need on the
front-end. The result has been a lot of buggy and lackluster front-end code.
Node.js gives teams a compelling reason to master JavaScript, and to learn
tools like CoffeeScript. And that's great news for the web as a whole.

~~~
dumbphone
'With Node and a framework like Express, you can understand things at the
level of "let me look at this HTTP request and decide how to respond to it."'

Sure, but roughly the same kind of thing is available in most other serverside
languages. Python has Flask, Ruby has Sinatra, and PHP also has several mini-
frameworks.

~~~
TrevorBurnham
Right, I like Sinatra a lot. But there's substantially more magic there than
in Express, which is actually a pretty thin (yet powerful) wrapper around
Node's low-level HTTP API.

------
zeemonkee
There's a lot to like about node.js - I'm playing with
node+express+coffeescript right now, and it's fun.

That said, some things I don't like so much:

\- "inception" style development. Callbacks within callbacks, especially if
you are doing db queries for example. Gets cumbersome and annoying very
quickly.

\- lack of ecosystem. Though improving, nowhere near Ruby, PHP or Python (or
Java/JVM for that matter).

\- lack of use cases. Hard to say where it would be a valid replacement for
existing webapps. Chatbots and games, sure, but most client work I do is
boring old CRUD. Rails and Django provided huge productivity gains here,
nodejs, not so much.

\- hype. I get the feeling a lot of this is driven by front end developers who
suddenly feel they've been given the keys to the server-side kingdom without
having to learn another language. Much of what node.js offers exists elsewhere
and better, for example Haskell or Erlang (though not as accessible to mere
mortals, perhaps).

------
tree_of_item
> 1 - Javascript is not fundamentally easier to code in than Java.

What makes you think this? I think the idea that Javascript is a better
language than Java is a big part of what draws people to things like Node.js.

~~~
VMG
His point makes even less sense when you consider CoffeeScript

~~~
barnaby
+1 because once you remove all the embarrassingly bad syntax from javascript,
and use only the good parts, the way coffeescript does, then you have one of
the best languages on the market (minus step debugging and tooling support...
but those are coming soon).

------
ionrock
One caveat before commenting is that I haven't written a major app in Node.js
and I use Python most of the time (vs. Java).

I don't think the decision to use Node.js should be based on the fact it uses
Javascript. Currently, Javascript has a much more interesting ecosystem than
it has at any other time. Just as Rails took many collective practices and
managed to communicate them clearly to a huge group of developers, I think a
similar trend is happening in Javascript. From this perspective, Node.js is
appealing because it rides atop this Javascript revolution with tools like
Coffeescript, Backbone, etc.

Outside of the language decision, I think people are choosing to use Node.js
b/c of its programming model. There are many applications that are relatively
easy to code for when you can assume a constant connection between two
processes. Where Node.js seems to excel is in these service level, socket
based servers that may or may not have a web component. Likewise, Node.js also
aims to be very _nix friendly in that it tries to use simple processes for
scaling instead of relying on more complicated application / language specific
tools. This adherence to_ nix patterns is also very advantageous to some
people.

Finally, as people start finding use cases where async really is a good idea,
Node.js ends up being a decent option. Having done some async programming in
Python, it is very difficult because the async assumption needs to be made
throughout in order to avoid blocking. My impression is that the experience in
other languages is similar, where no library is truly able to make the async
paradigm seamless. Node.js has been written from scratch to support this model
and many developers understand it via their Javascript experience. It
therefore can be a good option when compared to including something like
Stackless, EventMachine, etc. in their applications.

I think the key point here is that Node.js has managed to hit something of a
sweet spot in that it is async, uses a language that is having something of a
renaissance and uses *nix to make its integration obvious.

Again, I don't use Node.js very heavily at all, but that is my impression as
to why people would choose it over other technologies.

------
raniskeet
"The reports of having 100k connections is great but again, any server in C or
Java written correctly should be able to do the same thing..."

Only a few people can write them correctly besides, they're not fun to hack
with. Feels like work.

------
pschlump
I just finished coding a web service in both Java, PHP, and node.js. Java took
1848 lines of code. PHP 548. Node 201. In my tests Node uses much less CPU and
has way better performance than Java or PHP. 201 lines is far easier to get
working than 1848.

------
wingo
I have no love for callback-based programming, but assuming you want to do it
(node.js), you really need closures, which Java does not have.

------
karterk
> 1 - Javascript is not fundamentally easier to code in than Java. I wouldn't
> make that statement with Ruby for example, but I've done lots of all 3.

A lot of people coming from front-end development on the web prefer JavaScript
over Java.

Personally, to me (and probably a lot of people who are actually working on
serious projects on node) - node fits beautifully in certain contexts. For
e.g. socket based streaming is ridiculously easy using socket.io.

Callback based programming is not fun - but once you get used to the syntax,
it's not unbearable either.

------
Meai
Well this is not an answer any single person can or should want to give you,
but I'll try to summarize the big picture anyway:

1\. Nodejs is really well documented code. This is very rare, and much more so
in the Javascript world.

2\. It has a nice, easy to use package manager. In comparison, I have a hard
time containing my boiling rage over Maven...

3\. Nodejs was marketed as very fast. Although async+fast solutions exist with
other languages and frameworks too, they require you to be very knowledgable
in those areas. Nodejs is a no-brainer. They practically guaranteed you that
you are not going to get bad performance, because in Javascript you can't use
blocking calls. Nodejs users care about performance. Java programmers tell you
to not worry about it. (attention: gross generalization)

4\. Javascript programmers don't know about better solutions. In fact, I'd say
that most of the PHP crowd doesn't know better solutions either. There's your
huge market.

5\. Javascript is easy to program in. You can have your _production_ server up
and running with a few lines of code. I believe an experienced Java programmer
when he says that the LOC (lines of code) are not much more with Java. But you
do need to learn a lot more to get to that point. Nodejs is self-contained.

Personally, I do not want to program large projects in a dynamic language. I
still made a small prototype in Nodejs before moving on though. It's too messy
for me :)

------
floby
The important part in Node.js is not "js" it's "node". The design pattern
encouraged is a network of micro-utilities nodes.

Ryan Dahl (node.js creator) did not choose javascript because it was cool but
because the language was the most suited to its needs. In fact we started
several project based on the same principles in different languages (C, lua,
and others). Javascript is a good fit because it has no previous history on
how to do I/O (which is the main focus in node.js design) except AJAX. It sure
has been very helpful in making it popular. But the point is that there could
have been Node.whatever. [1]

Now if you choose to use Node.js because it's cool, that's fine, but you're
missing the important points :

1 - It is easy to write. Yes it is. Not only because it's javascript (or
coffeescript) but also because the API is very well designed. Because of the
agreed on convention of coding, it's also very easy to use modules even when
these are not as much documented as node itself. It also would not be as easy
to write if it were C or Java. In this netty example [2] you need 4 different
classes to write an echo client/server which sums up to approx. 120 lines of
code without comments and imports. The node version is 15 lines long at best
[3] and clearer.

2 - It is efficient. Sure, in raw calculation, lots of other languages are
faster. What makes node efficient is asynchronous I/O. You can do async I/O in
any other programming language. It's just not that easy and most importantly
you don't have to if you are lazy. The fastest language to write async I/O in
is probably C. And you can do just that using libuv, the C library behind
node.js which is incredibly faster without the Javascript layer.

3 - It works at the session/presentation level. Of course it's not as
convenient as writing your php file, but it's necessary to ensure that the
async model is respected (which is what makes it efficient, which is the
reason why you came here in the first place). If you want cool javascript to
replace php/JEEE/asp, you can use Jaxer.

Of course there are other important points that I'm missing here both because
they don't come to mind at the moment and because you should experiment by
yourself.

[1] <http://www.youtube.com/watch?v=L_JKb61EalQ> [2]
[http://docs.jboss.org/netty/3.2/xref/org/jboss/netty/example...](http://docs.jboss.org/netty/3.2/xref/org/jboss/netty/example/echo/package-
summary.html) [3] <http://nodejs.org/>

------
metajack
> 1 - Javascript is not fundamentally easier to code in than Java. I wouldn't
> make that statement with Ruby for example, but I've done lots of all 3.

It depends on what you are writing. But personally, I find that languages with
first class functions are much more powerful than languages without. Closures
fall out of this as well. So on that point, JavaScript stomps all over Java.

From the anecdotal evidence of all the infrastructure the Node community has
created, I'd say the FFI must be substantially better as well. I've coded in
JNI and it was not fun. There's a lot of good code already out there that
doesn't run inside a JVM, and to many, it's pretty important to be able to
access that.

------
DennisP
Node isn't entirely javascript. The http parser, for example, is a very fast
implementation in C.

The javascript part is taking advantage of a big race between several major
vendors to make a really fast javascript implementation.

In tests of massively concurrent loads, node.js is very fast and reliable.
(That's not to say it's the only good solution.)

The libraries are entirely asynchronous. They put an emphasis on making it
easy for an average programmer to get things right, instead of running into
hidden pitfalls.

(I haven't used it in anger yet, but I hung around on the mailing list for a
good while.)

------
jrussbowman
1) What language is easier to code in is really determined by the proficiency
in various languages of the developer.

2) Performance is not all that matters. Getting back to the easier to code
argument, productivity is equally as important. If the developers of the
product are more proficient in Javascript, then working around the performance
issues is likely cheaper than waiting for the developers to learn another
language better, or to hire developers who know Java or C or whatever and
understand the vision of the product being created.

Not to mention these days performance is cheap. Run several instances of
node.js behind some sort of load balancer/proxy on a multi-core server and
you're good to go. Heck, my little cheap Rackspace cloud server has 4 cores
available to it.

The language and platform is only part of the equation to developing a
product. Whatever allows you to create a product you can develop quickly and
maintain in the future is the right choice.

Disclaimer: I tried node.js, decided it wasn't for me and went back to Tornado
(python). I however can understand why someone more proficient in javascript
would choose node.js. It was really easy to set up and get into writing code
with.

~~~
dumbphone
"productivity is equally as important"

Node has a lot of good features, but programmer productivity isn't one of them
currently. There are close to zero full-featured frameworks with "the works"
(Geddy comes close, but is no longer maintained, and Express is essentially no
more than a mini-framework). You simply have to write a lot of code yourself
to do stuff that in other frameworks such as Django is included by default.
Add to that the fact that deploying a Node site isn't nearly as easy and fast
as deploying a PHP site, and you've got a setup that isn't ideal in terms of
productivity.

------
iambot
though not a great justification, and I'm hoping hackers far better than
myself can defend nodejs (if only for my entertainment/interest). But using
node is actually VERY fun, I cant quantify it but I find it a lot more
enjoyable than any of the other server side languages I know.

~~~
iambot
and using it in conjunction with coffeescript only increases the pleasure of
working with it. I can only but dream of the day that coffeescript needn't be
compiled into JavaScript first.

------
sbalea
I, too, do not understand why anybody would use Node.js... when you have
Erlang :)

And since you speak of Java, I also do not understand why anybody would use
that either. If you have a thing for the JVM, at least do yourself a favor and
use a decent language, like Scala.

~~~
jesboat
Erlang's syntax is terrifying to users only experienced with more mainstream
languages, and hard to work with for users not specifically experienced with
it. LFE or Reia may solve some of those problems, though I don't have
experience with them.

~~~
sbalea
Erlang syntax is just that, a (quirky, different, non-mainstream) syntax.
Takes about 2 weeks to get used to, and it's simpler than, say, C syntax. The
core concepts, such as functional programming and the Actor model will be
harder to grok for an imperative-bred programmer, but I think it's totally
worth it, at least for the perspective that it will give you.

Speaking of Reia, its author just announced he's stopping development on it.
There's another, similar project called Elixir that is considered to be Reia's
spiritual successor.

------
olegp
Having moved on from Java to JavaScript on the server, I strongly disagree
with the first point. I've had the pleasure of rewriting a webapp I had
previously written in Java in JavaScript and found the latter to be much more
compact and easier to maintain, largely due to JavaScript's dynamic nature.

My only gripe with Node is the obsession with the asynchronous programming
style and overly eager use of callbacks. However, there are workarounds, such
as my Common Node library (<http://olegp.github.com/common-node/>).

------
Tichy
Ymmv - personally I think JavaScript is a lot easier than Java, but Ruby might
actually be harder than Java as the Ruby docs are very messy. I still prefer
Ruby to Java, though.

------
ThinkEzy
I used Python as a scripting engine and it is fabulous. I see a similar role
for node.js.

------
swlkr
I use node because it's fun.

------
whiterabbit
You can't program the client in Java.

~~~
pixeloution
And how is that relevant? I've heard the argument "Your backend developers can
work on the front end too" -- but its a tired argument. Any developer who
can't already do both has no place working for a company producing web-based
software.

~~~
whiterabbit
Ideally, would you write your web application using one language, or ten?

And that is how it's relevant. Any developer who can't grasp this concept has
no place working for a company producing web-based software.

~~~
sofuture
I would choose to write it in however many languages fit the various pieces
best. To choose otherwise would be ill-advised.

~~~
whiterabbit
By "however many languages fit the various pieces best," did you mean the most
or the fewest?

~~~
sofuture
I mean I wouldn't make technical decisions dogmatically.

~~~
whiterabbit
I think everyone here will back you up on that, but don't infer that zinxq is
advocating choice by technical dogma. I read their post as simply asking for
an explanation for node.js's accelerating popularity; of course there are many
factors, but its ability to reduce lexical context switching is obviously a
major component. To argue otherwise would be ill-advised.

