deferred

Node.js Promises using when/then

Doing tasks then doing other tasks... then doing other tasks... is a core problem solved by asynchronous programming. Node.js, in combination with some additional libraries, offers a vehicle for unhooking an application workflow from sequential processes. Here's a quick look at a script demonstrating the deferring of certain tasks until others have completed. In this example, the output in the console would be:

bam
i said: bam

After one second "bam" is printed. Then another second later "i said: bam" is printed.