An Introduction to node.js

0 15
Avatar for potta
Written by
4 years ago

node.js is a Javascript runtime built on Chrome's V8 Javascript engine.

node.js is NOT a programming language!
node.js IS a runtime!

If you know Java, a simple analogy to understand this is node.js is similar to the Java Runtime Environment and the V8 engine is like the JVM where the applications are actually run.

node.js now enables Javascript to be run on your machine with access to I/O, file system etc. where once Javascript was only used to manipulate the DOM. Now you can do much more with Javascript than making websites interactive.

What is Blocking IO?

Typically when a web server receives 2 requests request1 and request2, the request2 is not initiated until the request1 is fully completed. This is where the web server would have to create multiple threads to concurrently process multiple requests. But Javascript is single-threaded! So how do we solve this issue?

Non Blocking IO

In this scenario, request1 and request2 are made asynchronously without having to wait on each other and also without having the need to have multi-threading. This is where node.js really shines!

So the best use cases for node.js are when you have an I/O intensive application which can either be using the file system or HTTP requests to an API.

node.js is not the best solution when the operations are CPU intensive in which case it might not make sense to use a lot of asynchronization.

More coding stuff in my YouTube channel - https://www.youtube.com/channel/UC1DV3Dc3D-YEXMKoFJNOvWQ

1
$ 0.01
$ 0.01 from @TheRandomRewarder
Sponsors of potta
empty
empty
empty

Comments