Getting started with NodeJS

node

Please read this to get basic information about node js. don’t like to write too much..

About me

How to install ?

You can google it.. or else I got one link please refer this.

let me go with basic example which is also given there in about me section. nodejs is really helpful for building a scalable network programs.

Basic Echo Server

var http = require('http');
var s = http.createServer(function(req,res){
	res.writeHead(200,{'content-type':'text/plain'});
	res.end("hello word");
});
s.listen(8000);

woow..  few lines of code and we’ve done with basic server..  🙂

Run :

use bellow command to run this app

node basic_server.js

Fire request on our server

1) using curl : curl http://localhost:8000

2) using url : http://localhost:8000 (in browser)

Advertisements

Network Information API

How to detect Network Connection changes ??

Do you have same question sometime in ur mind ? hmm.. i got answer from MDN

This API provides information about the system’s connection, such as connection bandwidth of user device, or whether the connection is metered.

Usage :
This can be used to select hight definition and low definition content based on the user’s connection.

Detecting connection changes

var connection = navigator.connection || navigator.mozconnection 
|| navigator.webkitconnection;
function updateConnectionStatus(){
alert("connection bandwidth="+connection.bandwidth +"Mbs");
if(connection.metered){
alert("the connection is metered");
}
}
updateConnectionStatus();

Simple JS Code ..!!@@