Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TJ Holowaychuk's criticisms of NodeJs

Tags:

node.js

Back story, read: https://medium.com/code-adventures/4ba9e7f3e52b

TJ says node fails because:

  1. you may get duplicate callbacks
  2. you may not get a callback at all (lost in limbo)
  3. you may get out-of-band errors
  4. emitters may get multiple “error” events
  5. missing “error” events sends everything to hell
  6. often unsure what requires “error” handlers
  7. “error” handlers are very verbose
  8. callbacks suck

Can someone inform on the issues TJ mentions? For example, I've never seen problems with callbacks being double-executed. Under what conditions would it/they occur?

EDIT For those voting to close: If you don't know who TJ is, he's responsible for the majority of npm modules. So this isn't "idle" ranting by an uninformed user. His departure will greatly hurt nodejs and this question attempts to get answers as to specifics of the criticisms. I never see these issues. Do you?

like image 414
JasonS Avatar asked Jul 05 '14 08:07

JasonS


People also ask

What are the problems with node js?

Common Node. Uncaught exception or error event in JavaScript code. Excessive memory usage, which may result in an out-of-memory error. Unresponsive application, possibly looping or hanging. Poor performance.

For which NodeJS is not recommended?

js receives a CPU bound task: Whenever a heavy request comes to the event loop, Node. js would set all the CPU available to process it first, and then answer other requests queued. That results in slow processing and overall delay in the event loop, which is why Node. js is not recommended for heavy computation.

Is node js going away?

The short answer is “NO.” The long answer is, “NO, it's not dead, and it probably will never die.” Node. js is just as relevant to coding in 2021 and beyond, even if the hype around it has stabilized slightly.


1 Answers

1: can happen, when you wrap a stream in a function:

function doSomething (callback) {
    var stream = createStream();
    stream.resume();
    stream.on('end', callback);
    stream.on('error', callback);
}

so, what if end fires, then error fires?

2: the same thing, what if nothing fires (remove stream.resume for example)? This obviously a bug in the function, but what you see is that everything just hangs.

4: you naively hook some asynchronous functions to emit error events from emitter, then when the error occurs, a listener tries to destroy emitter, causes another error event and ends up in an infinite loop.

5,6,7: each emitter without error listener can potentially crash your app. You have two options: try to understand where it is safe to omit one or add them explicitly everywhere.

8: debatable. TJ is a proponent of coroutines, so it's just his opinion.

like image 69
vkurchatkin Avatar answered Oct 02 '22 05:10

vkurchatkin