Hello Friends, We are hearing a lot about the JavaScript programming on the server side with the help of Node.JS. And I would say that Node.JS is not quite new. I this article I will help you to understand you first hello world program in Node JS. But before going further and writing first Hello World program in NodeJS. Lets have a look at the history of this programming language.
Ryan Dahl first proposed the language in 2009 but there were not many takers of this server side JavaScript programming language. But slowly and steadily the language made its inroads in the technology and internet world.
And today it is one of the most used server side language along with MEAN stack.
This is the First article in the series for NodeJS free article on this blog:
- Writing my first Hello World program in Node JS
- Simple Trick to create a NodeJS Server on Windows/Ubuntu
- Parsing the Query String, HTTP Method, request Path and payload for NodeJS
What is Node JS?
- Node JS is server side JS runtime environment built on chrome’s V8 JavaScript Engine.
- Node JS packages the javascript file and sends them to V8 engine.
- Node js is C++ application that embeds the V8
- Node JS now presents itself as two applications: a script processor and a REPL (Read Eval Print Loop)
- Script processor is simply called by the name of the script file and executed by node {script name}.
- The above command does not simply sends the script file to V8 engine. In fact it first initializes the process called event loop and then it initializes the initial parts of your JS file and then it processes the event loop.
- The event loop is an infinitily completing task which starts as soon as it completes. Each part or tick consists of the Node JS continuously checking if there is anything else to process.
- There can be synchronous and asynchronous tasks added to the node js file, The event loop takes care of the asynchronous tasks and keeps checking if there are more tasks to be completed,
- Node JS is single threaded application. Node’s event loop and “non blocking” IO don’t allow Node to do multiple things at one time, it just allows node to schedule things later.
That’s enough of the introduction about the NodeJS. Lets get started and get our hands dirty with some non stop fun.
Installing Node JS On Windows and Linux
NodeJS can be installed by using the installers which can be downloaded from the below page:
https://nodejs.org/en/download/
Alternatively you can install NodeJS from package manager as mentioned in the below articles.
Windows: https://nodejs.org/en/download/package-manager/#windows
Ubuntu based Linux Distribution: https://nodejs.org/en/download/package-manager/#debian-and-ubuntu-based-linux-distributions
After Installation
Once NodeJS is installed on your system. You can start writing your first Hello World program in Node JS as shown in the video below:
Since I am learning Ubuntu and Linux in my free time. I tried writing my first NodeJS program on Ubuntu. But you can use the same steps to create a first Hello World program in NodeJS.
Steps for Windows:
- Create an Index.JS file in a folder of your choice.
- Change the contents of Index.JS file as shown below:
var app = {}; app.HelloWorld = function() { console.log('Hello World again'); } app.HelloWorld();
- Once the file is edited. Save the file and open the same folder in command prompt.
- Consequently type the command node index.js
- Finally you can see the output in the command prompt.
Leave a Reply