All Case Studies Design Development Interviews Our Way Project Management

Node.js FAQ: Everything You Want to Know About Node.js But Were Afraid to Ask

Choosing a technology for your web application is one of the most important decisions you will make for your business. If you make the right choice, it will lay the foundation for further growth. A wrong decision can cost you a pretty penny.

Node.js has been a trending technology, and companies such as Netflix, LinkedIn or Paypal decided to leverage it in their stack. It facilitates the efficient building of fast applications, but it is not the best fit for all cases. If you are considering using Node.js for your app, go through the questions below and see whether it meets your expectations and needs.

What is Node.js and how does it work?

Node.js is a Javascript runtime built on top of Chrome's high-performance V8 engine. Thanks to it, your JS code can run almost as fast as the one written in Java.

What are the main benefits of Node.js?

First of all, the Node.js community is very active and always eager to help. Thanks to their support, the quality of the packages consistently improves. Secondly, although Node.js is easy to use, it still offers a range of possibilities in development. Thirdly, it makes it possible to write both the front end and back end of an app using one developing language: JavaScript. It improves the communication between teams and makes work more efficient. In effect, chances are your app can be built more quickly. Finally, the non-blocking IO system makes Node.js blazing fast.

Read more about pros and cons of Node.js.

What kind of applications can you build using Node.js?

Actually, you can build just about anything with Node.js, but that won’t always be a wise choice. Where Node.js excels is dealing with multiple I/O operations and realtime systems. Due to its event-based nature, it handles such cases more gracefully and much faster than other languages or frameworks.

When shouldn't I use Node.js?

Node.js is not a good match for CPU-heavy software. Long-running calculations block incoming requests, which can lead to a drop in performance.

Can Node.js be used for machine learning?

Node.js can be used for anything, but it might be not the best tool for machine learning. Due to its single-threaded nature, Node applications are not particularly good at heavy-task computation such as machine learning. In some cases, Node.js might still be good enough, for instance, for basic regression, classification or feature extraction. If you would like to add machine learning to your application, you should consider using Python with Tensorflow or Theano.

Which hosting service should I choose for a Node.js website?

Node.js is “hosting agnostic”. It means that it can be run easily on any server provider, including Amazon Web Services, Azure and Google Cloud. However, according to a recent Stack Overflow Survey, it seems that most Node.js applications are hosted on AWS. If you want to review all the available options, check out our guide to hosting Node.js apps.

Which database to use for Node.js?

Just like with hosting providers, Node.js can work with any database, both NoSQL such as MongoDB and SQL ones, e.g. Postgres. There’s a notion that using NoSQL-based databases is much easier with Node.js. That’s because you don’t have to declare a strict schema in such databases and, most importantly, you can easily convert any entry from the database into a Javascript object. That’s a double-edged sword, though. Without a strict data definition, you may end up with inconsistencies in your application critical for your business.  

What are Node.js modules?

Node.js modules are just libraries and third-party pieces of code that developers can use to make their work much faster. If you’re familiar with Ruby, they are the equivalent of gems.

Modules are also the thing that makes Node.js such a great choice. The numbers of modules on npmjs.com, the primary Node.js modules registry, is steadily growing thanks to the really active community.

See also: 17 Most Helpful Node.JS Open Source Projects According to Experts

Will my NodeJS application be faster than using competitive solutions?

Node.js is just a tool, which can be used in a bad and in a very good way. Just choosing Node.js will not solve any of your performance problems, if if the code isn’t written well. However, when it comes to basic HTTP request benchmarks, it appears that it handles massive amounts of traffic better than Ruby on Rails or some other solutions.

Will I have trouble finding developers to work on my application? What's the average supply of NodeJS developers on the market?

According to the Stack Overflow Survey from 2017, Node.js continues to be the most popular and one of the most demanded skills on the market. Its popularity is constantly growing, and so is the number of developers.

What does it mean that Node.js is single-threaded?

That’s not entirely true. Node.js is single-threaded from a developer’s perspective. Everything related to JS code is executed on a single thread, but Node.js does spawn child processes for some asynchronous tasks, such as file operations, network operations or database queries. These tasks are “invisible” for the programmer and run deep under the hood. It’s also worth mentioning that these threads don’t run any JS code nor block the event loop.

What does it mean that Node.js is event-driven?

Simply put, event-driven means that there are some events dispatched when a given action happens, and we can use such an event to perform an equivalent action. The event-driven nature derives from the asynchronous aspect of Node. There is an EventEmitter inside Node.js’s core, and it’s responsible for dispatching/receiving messages. This is crucial when we want to monitor the state of reading a file or listen to incoming connections in order to respond with data.

How can I scale Node.js application?

There are two ways to scale Node.js application: horizontally and vertically. Due to the single-threaded nature of Node.js, running it on a 16-core server by default does not give any performance gain versus running it on a single-core system. That’s why you have to take care of vertical scaling too. It means that you need to run multiple instances of your app inside one machine and spread the traffic across CPU threads.

Fortunately, Node.js gives us module called cluster, which is very helpful. However, from our experience, we recommend using pm2, which is more reliable. You can read more about the vertical scaling of Node.js apps in this article.

When it comes to horizontal scaling, it works similarly to any other backend application.

How does the event loop work?

Generally speaking, the event loop is a mechanism that waits for and dispatches events or messages in a program. In Node.js, event loops are the central control flow constructs. For example, every time a request is about to be handled, it’s put on the event loop and processed as soon as it’s ready to be processed. Node, instead of doing it on its own, delegates the responsibility of handling the system. Because of such behaviour, Node is not actively waiting for this task to finish and can handle other requests in the meantime. The event loop makes Node.js faster and more efficient than other technologies

Want to know more about Node.js?

We believe that our list might not have exhausted the subject. If you want to know more, leave us a comment or write at hi@netguru.co. Our experts will dispel your doubts and help you make the right decision.

Node.js companies
Follow Netguru
Join our Newsletter

New Call-to-action
READ ALSO FROM NodeJS
Read also
Need a successful project?
Estimate project or contact us