The code below is a nodeJS code. I am new to nodeJS and i am pretty confused with the flow of code in a nodejs since it tells that nodejs is single threaded and in the other hand it also tells us that the callbacks and IO are asynchronous if i am not wrong. Can anyone give me the actual meaning of callbacks and how the code is working. Is it so that the asynchronous function which we are calling as callbacks are executed by some other thread/process and not by the single nodejs thread (P.S-It is the concept what i understood...i may b wrong), then why we r callng nodejs as single threaded program.
function placeOrder(orderNo) {
setTimeout(function() {
deliver(orderNo);
}, 5000);
console.log("Order is: " + orderNo);
}
function deliver(orderNo) {
console.log("Item is delivered with Order No.- " + orderNo);
}
placeOrder(1);
placeOrder(2);
placeOrder(3);
placeOrder(4);
placeOrder(5);
placeOrder(6);