Posts

Showing posts from March, 2018

Promise method of Node JS and how it simplifies the callback problem

Hi guys,Today we will see how  we can avoid callback problems by Advanced method of node Provided by Node version 6.5.0 (or further version). Its Promise method.You don't need to include any library for that.Below  is the example. function asyncJobFunction() { var url="mydomain.com"; return new Promise(function(resolve,reject){ //Write here your Async Code call.Get(url,function(err,data) { if(err) { reject(err); ///Reject the Promise by calling the reject method. } else { console.log("Success"); resolve(data); ///Resolve the Promise by calling the resolve method. } }) }) } above we have written one function asyncJobFunction which returns the promise object.so we have to catch the result either resolve or reject. lets see how we can catch that. var promiseData=asyncJobFunction();  promiseData.then(function(result){ console.log("Success"); console.log(result);  /...

Introduction to Node JS and How to Overcome Callback Problems in it

Introduction:-  As you all know,Node.js is a server side platform built on Google Chrome's Javascript Engine(V8 Engine).It provides a rich library of various JavaScript modules which simplifies the web development to great extent. Node js runs asynchronously with single thread that's why its faster compare to others. But Sometimes it can make you worry a little because If you have worked on java or other technologies which executes synchoronously,there you dont need to worry about how two functions will execute because those were running synchronously.It can wait one after another. In Node JS,its not the same case.Second function will execute before first function if first function will take time.let me explain you by simple example. var x=0; for (var i=0;i<50;i++) {   x=x+1; } xyz(x); //Calling function xyz console.log("Hello World"); function xyz(x) {    //Time consuming code } In above case,It will first print Hello World before givin...