Wednesday 22 June 2016

How to Use Callback in Node.js

node.js-logo.png

A callback is a function which is highly used in node js. When we want to run any task after the success or completion of a given task then we will use a callback. We will write maximum API in such a way that they will support callback.

when we write localhost:3000/sum/23 on the browser then first it will call to the app.get('/sum/:num', sumCallback); routes. Then it will go to the sum function there we pass callback then we check number exists or not  if the number exists then on the success of the function we will move further else we will display error.

In else case we will call one more function sum there we also write one more callback. If sum function will return any result then inside sum callback will occur and display the result.

Read more about How to Use Callback in Node.js visit Findnerd.

No comments:

Post a Comment