In this blog post I am gonna give you all a brief idea about Node.js.
Earlier JavaScript was purely used for client side scripting, and it was embedded to a html page.But the node js developers use it for server side scripting(to produce the content of dynamic web pages before sending it to the user.) Node.js is an open source, cross platform run-time environment that executes JavaScript code server side.
Why node.js?
Node.js uses asynchronous programming.
When a file request comes a ASP/PHP file would,
Earlier JavaScript was purely used for client side scripting, and it was embedded to a html page.But the node js developers use it for server side scripting(to produce the content of dynamic web pages before sending it to the user.) Node.js is an open source, cross platform run-time environment that executes JavaScript code server side.
Why node.js?
Node.js uses asynchronous programming.
When a file request comes a ASP/PHP file would,
- Send the task to the computer's file system.
- Wait for the system to open and read the file.
- Sends the respond back to the client
- Get ready to handle the next task.
But as node.js is using asynchronous programming, it would handle the request in a different manner.It would,
- Send the task to the computer's file system.
- Handles the next coming task.
- Returns the respond of the first task to the client when the system has completed it.
In brief it reduces waiting and simply continues with the next requests.This is also known as the non-blocking I/O.
Now as you have an overall idea of what node.js is now let's get started with a simple piece of code.
Follow the below mentioned steps.
1.Before working with node.js you should have it on your machine.You can download it here
2.Now let's write a couple of lines of code to display "Hello" in the browser.
For that first create a node.js file with a suitable IDE (I will be using JetBrains WebStorm here).
2.Lets write the code to display "Hello" in the browser.After that we can run the server by typing "node <filename>.js" in the terminal.
3.Type http://localhost:8080/ in your brower and there you get "Hello" printed!
As now you have the ability to run a node application, it's up to you to go explore the more interesting stuff out there!!
Comments
Post a Comment