How to Use Callback in Node.js

Posted by Sachin Joshi
3
Jun 22, 2016
578 Views

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.

We will use most to the function using a callback in node.js.


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

1 people like it
avatar
Comments
avatar
Please sign in to add comment.