HNHacker News
TopNewBestAskShowJobs

alayek

118 karma · joined November 10, 2015

submissionscomments
alayek··on JavaScript is Eating the World
You've hit the bull's eye! Yes, and you're also not supposed to do much computation in Node JS code.

Some addition, subtraction is fine. But Array iteration, JSON encoding-decoding and similar CPU bound tasks could block the event loop.

You can perform them asynchronously, or forward the request to some remote service that's better at doing these computations for you and return results (maybe some service written in Python or a database)

alayek··on JavaScript is Eating the World
Other than their front-end build process, Node is also used in their user-facing servers. Basically, when your Netflix app makes a HTTP request to fetch any data from its backend servers, the request first hits a Node JS server.

Something like this: https://medium.com/the-node-js-collection/netflixandchill-ho...

alayek··on JavaScript is Eating the World
Node is single threaded, in the sense that your code runs in a single thread. Your code assigns microtasks, to be executed later.

Basically, if you write in Node JS, there's no concept of a thread. The thread API is not visible or accessible to the developer.

This forces you to think from the ground up about asynchronous operations that would take some time to complete - file opening, network requests etc., and have you group all tasks dependent on that time-consuming task, separately.

In Node, you are not supposed to block the event-loop that runs in that single thread and queues the tasks.

Node JS has shown over the years that it scales well (maybe not as good as Go or Elixir, but enough for most use-cases).

Node also offers lot of great tools, that can be easily added to your project via NPM / Yarn. The Node ecosystem has a solution for virtually any task you might need to do repeatedly in a project.

Just to be clear, I am not saying Node or its ecosystem is perfect. There's always room for improvement.

What I am saying is that what appears as an obvious flaw, is not really a flaw. The language allows other approaches to solve the problem.

← PreviousPage 2 of 2