Node.js is one of the most popular technologies nowadays to build scalable and efficent REST API's. It is also used to build hybrid mobile applicat...
For further actions, you may consider blocking this person and/or reporting abuse
Thanks for this clear article on how the things are done in background using nodejs....I have some question : what is the difference between worker threads and os threads....in prime number example why os threads are not used by default by libuv when doing CPU heavy task...what is the limit for the os threads...
As said in the article, your code must be written in C++ in order to be able to use the OS threads pool.
Hence the introduction of worker threads which can be used directly in JS.
Yeah, he is right :D.
That's why DB drivers are written in C++.
Thanks for the great post!
Let's say I need a worker to do heavy CPU calculations. How does the worker works under the hood? Does it start on a separate CPU core and uses this core by 100%?
What if a CPU has only one core? Will Node worker help with this case or it'll be useless to start a worker, because there are no free resources to split between the main thread and worker thread?
Thanks for commenting.
Node.js by default works in a single CPU core, so worker thread will spawn and execute in the same CPU core that the main thread does.
If you want to deploy a Node.js application across all CPU cores you need to write some code using
cluster
native module. Thanksfully there is a library called PM2 which does the dirty work for you and deploys a Node.js application in all CPU cores with its built in load balancer.The worker thread real problem is spawn like crazy, since creating a subthread (worker thread) isn't cheap (talking about CPU time and resources) but it's cheaper than fork the same process.
Well, if a separate worker and main thread are executed in one CPU core, then they share the same resource.
Is it correct that if we write heavy CPU code in "chunks", i.e. we will return execution context from a heavy function to the function which handles http requests with some interval, then we will emulate workers? But in this case it's not necessary for Node to allocate resources for a subthread, i.e. it's cheaper in terms of performance.
Remember Worker as OS thread actually so I don't think they will be emulated in a single CPU core case. Anyway that's an interesting question but unfortunately workers are pretty "new" so there isn't enough information about them.
@jorge_rockr amazing article, i learned a lot about nodejs.
Question: I am building a mobile-responsive website, and my stack has Nuxt.js (vue.js framework) for the front end, talking to back-end APIs in Laravel (php framework). Nuxt.js is built on top of node (I think?) and I am using it for server-side-rendering. What are your thoughts on this architecture, versus using something purely in node.js?
Hi! Thanks you so much for reading my article.
Yeah, Nuxt.js and Next.js (React) are built on top of Node.js and it's cool since you can use your Frontend knowledge adding some Backend code.
In fact, using pure Node.js could have a better performance but it could be more complex and hard to maintain.
@jorge_rockr it was a phenomenal article, thank you for writing it.
Thanks for the recommendation. Sounds like I should stick with back-end APIs in Laravel, and use Nuxt for my front end. Hopefully I should see a lot of the user-benefits one can get from using Node with server-side-rendering for SEO.
Node.js is also a variety of ready-to-use packages written for the Node.js, thanks to which we can easily connect to almost any service or database. The most common Node itechcraft.com/node-js/ integration dialect, however, is JSON, which speaks well with the NoSQL databases.
Excellent article!! Great Job! Really helpful for those who are new to NODE.JS .I cleared my all doubts regarding Node.js. Get more information about Node.js here.
Jorge Ramón, thank you for this awesome article!)
The company I am working at, in January-February 2020 starts the open-source project for Node.js developers (microservices)!
Warm welcome🥳
Spectrum: spectrum.chat/yap?tab=posts (community chat)
GitBook: manual.youngapp.co/community-edition/ (docs)
Twitter: twitter.com/youngapp_pf (news)
GitHub: github.com/youngapp/yap (docs)
(click🌟star to support us and stay connected🙌)
Thank you for sharing this awesome post! Node.js rocks🤟
My team just completed an open-sourced Content Moderation Service built Node.js, TensorFlowJS, and ReactJS that we have been working over the past weeks. We have now released the first part of a series of three tutorials - How to create an NSFW Image Classification REST API and we would love to hear your feedback. Any comments & suggestions are more than welcome. Thanks in advance! 😊
Wow! Amazing Article!
Thanks for sharing ❤️
Thanks for the great post!
Can I translate this article into Chinese so that more people can see it ?
Sure!!
Amazing! I'm surprised about how much you know about the internal process of Node.js, Can you suggest me some resources (aside of documentation) to learn advanced concepts?
Sorry for late response.
Take a look at this resources:
And check out this video to understand how Event Loop works (in browser but it's almost the same in Node.js).
Thanks Jorge, i'm checking them out right now!
Increible explicacion antes de este post no tenia ni la mas remota idea de como funcionaba Node.js en realidad, excelente
De nada!
As someone who is new to coding and just beginning to learn Node.js, this article was super helpful to get an overview of how Node.js works and why it's beneficial. Thanks for sharing!
Welcome! I'm glad it was useful for you
You might also like to visit : learnnodeonline.blogspot.com/
More blogs are about to come.
Yes, it's very powerful, but how to build dynamic sites that uses mysql db like PHP?
If you want to build a site in a PHP style you need a template engine.
There are many templates engines out there. It's better to use Express Framework and any of the following templates engines:
expressjs.com/en/guide/using-templ...
But if you really love PHP you can use it with Express Framework too:
npmjs.com/package/php-express
Thank you :)
Nice overview Jorge. Question for you - with the advent of asynch enabled REST endpoints in .NET, specifically Web API, does this mitigate the C10M problem you referred to somewhat?
According to Microsoft's official documentation:
Please note there is no thread dedicated to waiting for data from the request to come back, so that means they are not using Reactor Pattern (i.e. an Event Loop), they are really using purely OS resources (threads and interrupts) and that is awesome!!
I don't know if that's enough to solve C10M problem, maybe with big server resources such as 128 RAM, etc.
Thanks for the great post!
Thanks for the great article.
thanks for explaining worker threads more clearly!
Niceeeee post!