NodeJS Introduction for begineers

Krishnadeva Sathursan
3 min readJul 25, 2020
Node.js

Nodejs is an open source cross platform(implemented on multiple computer platforms) runtime environment for executing JavaScript code out side of a Browser. In earlier times, we use JavaScript for client side only. But now we can use JavaScript for server side too with the help of Nodejs. Whatever we can done by php, c# to build back end services are now easily done by Nodejs too.

What So Special about Nodejs than other back end building tools and frameworks like RAILS,DJANGO…..

#Nodejs is very easy to get start.

#Great for prototyping and Agile Development.

# Also used for building superfast and highly scalable services.

#It’s used in production by large companies such as PayPal, Netflix, Uber, Walmart and so on…

Advantages About Node App

Nodejs Architecture

Every Web Browser has a JavaScript Engine, that takes our JavaScript code and converts it to a code that a computer can understand.For example Microsoft Edge uses Chakra, Firefox uses Spidermonkey and Chrome uses v8 engine.

In 2009, Ryan Dahl, the creator of Nodejs came up with an idea , he thought it will be great to execute JavaScript outside of a browser. So, he took google’s v8 engine which is the fastest JavaScript engine and embedded it inside a c++ program and called that program “Nodejs”. So similar to a browser, Nodejs is a run time environment for JavaScript code. It contains a JavaScript engine that can execute our JavaScript code but these objects are different from the environment objects we have in the browsers.For example, we don’t have document object(document.getElementbyId(‘ ’)) instead we have objects can work with file systems(fs.readFile()) , listen for requests (http.createServer()) and so on. We can’t do these stuffs inside of a browser.

Nodejs is a program that includes V8 javascript engine plus some additional modules that gives us capabilities, not available inside browsers we can work with the file system or the network and so on. Both Chrome and Nodejs share the same JS engine but they provide different runtime environments for JS.

A single thread is allocated to handle multiple requests in Nodejs. This is called Non-blocking Asynchronous Architecture.So, requests do not want to wait for so long.

When a request arrives that single thread is used to handle that request if we need to query a database or thread doesn’t have to wait for the database to return the data. While the database is executing our query that thread will be used to serve another client. When the database prepares the result it puts a message in what we call an event queue. Node is continuously monitoring this queue in the background. When it finds an event in this queue it will take it out an event and process it. This kind of architecture makes node ideal for building applications that include a lot of disk or network access. We can serve more clients without the need to throw in more hardware.

--

--