Introduction to Node JS
Well, Today I'm going to start with node js.
First i will introduce what is node js.
This is used to web development. Node js is a server side application framework which built on google's chrome v8 engine. And also its based of our famous client side scripting language ''JavaScript'. Moreover it is completely free and open source. So anyone can use it !!. So why we not take a try with that??
Features of Node JS
Fast Performance
As i said above, its run on google chrome's V8 engine. Do you know?, V8 engine translate JavaScript to machine language. Thats the reason why it's fast action.
Asynchronus
We know, JavaScript also asynchronus non blocking I/O. Like that, Node JS also uses asynchronus non blocking I/O Model. So that, Node JS will not wait untill Input Output operations completes.
Single Threaded
Node JS runs on single thread. Even it runs on single thread, It can handle many more requests. Thats really advantage for popularity of node JS.
Node JS Libraries.
There are thousands of libraries available to work with node js. So we can use them to do many more things with Node JS. as example, we can use libraries to make pdf documents, send emails, connect with databases etc.
Here are some examples for Node JS libraries.
Practical Examples
Simple Hello World Program in Node JS
//This is the simplest example of Node JS.
//This will print Hello World in browser console.
console.log("Hello World!");
we can show this Hello World in browser page in <H1> tag. To do we need to import "http" library. Its a commonly used library which comes with Node JS. Using that library, we can send our Hello World message to browser (Client) via http response.
const http = require('http'); //import http library
//Configure Node JS to respond '<H1>Hello World</H1>' for all http requests
//set start server to listen on 3000 port
http.createServer( (req, res) =>{
res.setHeader('Content-Type', 'text/html'),
res.write('<H1>Hello World</H1>'),
res.end()
}).listen(3000);
//Enter localhost:3000 in browser URL, We will get Our Hello World!!
Those are just very simple examples as they are only for introduct basic Node JS functionality. There are many more advanced, complicated things we can do with Node JS. And also we can use Express JS like frameworks to work with Node JS more easily.
First i will introduce what is node js.
This is used to web development. Node js is a server side application framework which built on google's chrome v8 engine. And also its based of our famous client side scripting language ''JavaScript'. Moreover it is completely free and open source. So anyone can use it !!. So why we not take a try with that??
Features of Node JS
Fast Performance
As i said above, its run on google chrome's V8 engine. Do you know?, V8 engine translate JavaScript to machine language. Thats the reason why it's fast action.
Asynchronus
We know, JavaScript also asynchronus non blocking I/O. Like that, Node JS also uses asynchronus non blocking I/O Model. So that, Node JS will not wait untill Input Output operations completes.
Single Threaded
Node JS runs on single thread. Even it runs on single thread, It can handle many more requests. Thats really advantage for popularity of node JS.
Node JS Libraries.
There are thousands of libraries available to work with node js. So we can use them to do many more things with Node JS. as example, we can use libraries to make pdf documents, send emails, connect with databases etc.
Here are some examples for Node JS libraries.
- http - Can be used to communicate http requests.
- PDFkit - Generate PDF
- NodeMailer - Send Emails
Practical Examples
Simple Hello World Program in Node JS
//This is the simplest example of Node JS.
//This will print Hello World in browser console.
console.log("Hello World!");
we can show this Hello World in browser page in <H1> tag. To do we need to import "http" library. Its a commonly used library which comes with Node JS. Using that library, we can send our Hello World message to browser (Client) via http response.
const http = require('http'); //import http library
//Configure Node JS to respond '<H1>Hello World</H1>' for all http requests
//set start server to listen on 3000 port
http.createServer( (req, res) =>{
res.setHeader('Content-Type', 'text/html'),
res.write('<H1>Hello World</H1>'),
res.end()
}).listen(3000);
//Enter localhost:3000 in browser URL, We will get Our Hello World!!
Those are just very simple examples as they are only for introduct basic Node JS functionality. There are many more advanced, complicated things we can do with Node JS. And also we can use Express JS like frameworks to work with Node JS more easily.
Comments
Post a Comment