Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have heard a lot and read about the Javascript server side language i.e Node.js, and saw many comparisons in favor of Node.

I don't understand what makes it better or faster, or how it even relates to something as mature as Java Servlets.

But Servlets are built on top of a multithreaded programming language as opposed to Node.js. Then how can node.js be faster?

If suppose 1000K users query for a database records, then shouldn't Node.js be slower than Servlets.

Also Don't servlets have better security compared to Node.js?

share|improve this question
You should go learn basic concurrency models. –  Raynos Oct 11 '12 at 7:41
@Raynos Explain what you mean with this instead of being sarcastic in the comments. –  Florian Margaine Oct 11 '12 at 7:58
Both processes and threads can be used to scale any application for multi-core utilization. You don't need both. –  Raynos Oct 11 '12 at 16:00
@Raynos Can't the bound C functionality also be threaded? I just took JS's role to be as non-blocking auto-queuing messenger to hand things off to lower-level stuff but I still haven't gotten my paws on Node yet. –  Erik Reppen Oct 11 '12 at 21:28

1 Answer 1

up vote 7 down vote accepted

You're mixing apples and oranges, kind of.

Servlets (or inheriting from HttpServlet) let you access HTTP request parameters and respond with something, via (or on top of) an existing HTTP server implementation.

Although using Javascript as the language, Node.js is at a lower level than that. It starts from actually implementing the HTTP server. You can go on to doing more high-level stuff in it nonetheless, such as web applications.

About multi-threading, it's not necessary. Node.js servers aren't faster because of multi-threading, they're faster because they don't block on IO requests, so they can keep pumping them up in the queue, while doing other things. They only work when there's work to be done - they don't wait for it - and that causes a serious performance enhancement, as it turned out.

As for database queries, it's really more about constraints in the database model and API than it is about the client.

As for security - it's really a different topic, and is ultimately in the hands of any developer anyway, not so much in the library.

share|improve this answer
Servlet 3 supports asynch IO just like Node –  jiggy Jul 19 '13 at 15:33

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.