O'Reilly logo

Node.js Essentials by Fabian Cook

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 4. Debugging

At some point in your journey with Node.js, it is inevitable that you will have to debug some nasty bugs. So, let's expect them beforehand and plan for that day.

Logging

There are a few methods that we can use to debug our software; the first one we are going to look at is logging. The simplest way to log a message is to use console. In most of the previous examples console has been used to portray what is going on without needing to see the entire HTTP request and response, thus making things a lot more readable and simple.

An example of this is:

var Http = require( 'http' ); Http.createServer( function( request, response ) { console.log( 'Received request', request.method, request.url ) console.log( 'Returning 200' ); response.writeHead( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required