node.js

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.

Node.js, Turn debugging on for specific modules

Sometimes when working on a Node.js app, it's helpful to turn debugging on for particular modules. To do so, you can simply set an environment variable NODE_DEBUG when you start your app to flag which modules should output their debug messages.

Here's how to enable debugging for, say, the http, cluster, and socket.io modules:

$> NODE_DEBUG={http,cluster,socket.io} node app

Tags: