What is the node js?

Node.js for beginners, part 1 -What is node js?

Introduction
This is the first part in a series of tutorials I want to write on Node.js. I should make it clear that I’m no expert on Node.js,

This is the first part in a series of tutorials I want to write on Node.js. I should make it clear that I’m no expert on Node.js.

Node.js is an open-source server side runtime environment built on Chrome’s V8 JavaScript engine.
Node.js is free

Node.js uses asynchronous programming!

I decided to learn Node.js recently due to its increasing popularity. The programming industry moves incredibly fast and it’s dangerous to fall behind. Learning new languages is important because if you don’t you’re likely you’ll get left behind and out of a job. Think about all of them flash developers who can’t find any work anymore.

What Can Node.js Do?

1) Node.js can generate dynamic page content
2) Node.js can create, open, read, write, delete, and close files on the server
3) Node.js can collect form data.

Advantages of Node.js

1) Node.js is an open-source framework under MIT license.
2) Lightweight framework that includes bare minimum modules. Other modules can be included as per the need of an application.
3) Asynchronous by default. So it performs faster than other frameworks.
4) Cross-platform framework that runs on Windows, MAC or Linux.

Why Node.js?

I/O refers to input/output. It can be anything ranging from reading/writing local files to making an HTTP request to an API.

I/O takes time and hence blocks other functions.

Creating Hello World

Let’s create a hello world. First head over to http://www.nodejs.org¬†and download node.js. When it’s installed and ready create a new JavaScript file with the following:

console.log("Hello World");
Now save the file, call it something like “hello.js” and run it with the following command:
node hello.js

you want to know how to print ‘Hello World’ to new HTTP connections.

Open your text editor and type:


var http = require("http");

http.createServer(function (request, response) {
   // Send the HTTP header 
   // HTTP Status: 200 : OK
   // Content Type: text/plain
   response.writeHead(200, {'Content-Type': 'text/plain'});
   
   // Send the response body as "Hello Stack Developer"
   response.end('Hello Stack developer\n');
}).listen(8080);

// Console will print the message
console.log('Server Started');

Now save your file and run it with:

node hello.js

You should see ‘Server started’ in the terminal. Great! Now open your web browser and go to ‘http://localhost:8080’ you should see your ‘Hello World’ message.

The first line is just getting the http module and saving it to the variable ‘http’. The http is included with Node.js to make it easy for us to create Node.js applications.

I thing Better understanding of Node js tutorial.

Social Share

Leave a Comment