Unless you have been living in a cave in the past several years, you must have heard something about "NodeJS" or just "Node" by now.
So what is it and what's all the noise is about?
In short, it is JavaScript running outside the web browser. Wait,.... what? ....... JavaScript has always been running in a web browser, hasn't it?
Well, not anymore since 2009. Now it runs outside the web browser, but where? .... On the Google's V8 engine. (Sometimes it is called the Chrome V8 engine). V8 engine can convert your JavaScript code to machine code and run it out side the browser.
Now don't ask "So What? .....". Because this means, if you are developing on a web application, now you can add stunning behaviors in the client side, as well as complete all the server side scripting with JavaScript.
This is the reason for the aforementioned noise, and the reason for JavaScript to become one of the most highest demanding skill in the past several years.
To get started with NodeJs, you need to install it first. Go to nodejs.org, and download the installer.
Once the installation is complete, start the command prompt.
Now lets go through some basic Node commands.
01. "node -v"
This command will give you the current version of Node installed. If this command works, that simply means NodeJs has successfully installed on your system.
02. "node"
This command will start a new node process, and keep waiting for JavaScript. For example, now you can type some valid JavaScript like the following and get it complied.
Just so if you failed to notice, important thing here is that we are running JavaScript, NOT in a browser. This new node process is actually running on the V8 engine.
We can quit the process by pressing "Ctrl + C" twice, or with the command "process.exit(0)"
03. ''node <filename>.js"
3.01. Create a folder called "NodeTest" somewhere in your hard drive.
3.02. Open any code editor which you like. (I am using "Atom")
3.03. I am explaining with Atom editor here, but this can be any editor. Click on "Open Project"and select the "NodeTest" folder in the file browser.
3.04. Right click on the "NodeTest" folder in the "Projects" panel and choose "New File"
3.05 Name the new file as "test.js" and type the following code in it. You are very much welcome to substitute your name instead of mine.
console.log('Hello World');
var myName = "Indunil Ranawake" ;
console.log(`My name is ${myName}`);
3.06. Now, brows into this "NodeTest" folder in the command prompt (or Terminal in Lynux)
3.07. type the command "node test.js" ("test.js" is the name of the file you created) and hit return key. This should execute the code and following result should be displayed in the terminal.
This means the following.
01. Node is successfully running in your machine.
02. Now you are capable of creating independent JavaScript files and run them outside a browser, much the same way you run a Java or C++ code.
The possibilities are endless !
We will explore as much as we can, in the coming posts.
Happy Learning :D
Indunil Ranawake
So what is it and what's all the noise is about?
In short, it is JavaScript running outside the web browser. Wait,.... what? ....... JavaScript has always been running in a web browser, hasn't it?
Well, not anymore since 2009. Now it runs outside the web browser, but where? .... On the Google's V8 engine. (Sometimes it is called the Chrome V8 engine). V8 engine can convert your JavaScript code to machine code and run it out side the browser.
Now don't ask "So What? .....". Because this means, if you are developing on a web application, now you can add stunning behaviors in the client side, as well as complete all the server side scripting with JavaScript.
This is the reason for the aforementioned noise, and the reason for JavaScript to become one of the most highest demanding skill in the past several years.
To get started with NodeJs, you need to install it first. Go to nodejs.org, and download the installer.
Once the installation is complete, start the command prompt.
Now lets go through some basic Node commands.
01. "node -v"
This command will give you the current version of Node installed. If this command works, that simply means NodeJs has successfully installed on your system.
02. "node"
This command will start a new node process, and keep waiting for JavaScript. For example, now you can type some valid JavaScript like the following and get it complied.
Just so if you failed to notice, important thing here is that we are running JavaScript, NOT in a browser. This new node process is actually running on the V8 engine.
We can quit the process by pressing "Ctrl + C" twice, or with the command "process.exit(0)"
03. ''node <filename>.js"
3.01. Create a folder called "NodeTest" somewhere in your hard drive.
3.02. Open any code editor which you like. (I am using "Atom")
3.03. I am explaining with Atom editor here, but this can be any editor. Click on "Open Project"and select the "NodeTest" folder in the file browser.
3.04. Right click on the "NodeTest" folder in the "Projects" panel and choose "New File"
3.05 Name the new file as "test.js" and type the following code in it. You are very much welcome to substitute your name instead of mine.
console.log('Hello World');
var myName = "Indunil Ranawake" ;
console.log(`My name is ${myName}`);
3.06. Now, brows into this "NodeTest" folder in the command prompt (or Terminal in Lynux)
3.07. type the command "node test.js" ("test.js" is the name of the file you created) and hit return key. This should execute the code and following result should be displayed in the terminal.
This means the following.
01. Node is successfully running in your machine.
02. Now you are capable of creating independent JavaScript files and run them outside a browser, much the same way you run a Java or C++ code.
The possibilities are endless !
We will explore as much as we can, in the coming posts.
Happy Learning :D
Indunil Ranawake
Comments
Post a Comment