Code coverage with mocha

I am using mocha for testing my nodejs application. I am not able to figure out how to use its code coverage feature. I tried googling it but din't find any proper tutorial. Please help.

You need an additional library for code coverage, and you are going to be blown away by how powerful and easy istanbul is. Try the following, after you get your mocha tests to pass (and have installed mocha globally):

npm install -g istanbul
istanbul cover _mocha -- -R spec
open coverage/lcov-report/index.html

Note the need to use _mocha instead of mocha, as explained here: https://github.com/gotwarlost/istanbul/issues/44

Blanket.js works perfect too.

npm install --save-dev blanket

in front of your test/tests.js

require('blanket')({
    pattern: function (filename) {
        return !/node_modules/.test(filename);
    }
});

run mocha -R html-cov > coverage.html