Skip to content
Ivan edited this page Jun 4, 2016 · 1 revision

How to debug modules

To be able to debug modules you'll need to place them in directory named node_modules which should be located in your project root directory or you can place your modules inside root directory itself.

Take a look at the flowing example:

Directory structure:

test.js code (main script):

 1  console.log('Debugging modules');
 2
 3  var m = require('mymodule');
 4
 5  m.print('Pure text');
 6
 7  m.print({
 8      id: 123,
 9      title: 'PhantomJS debugging modules'
10  });
11
12  phantom.debugExit();

mymodule.js code (module):

 1  exports.print = function (data) {
 2      if (typeof data === 'object') console.log(JSON.stringify(data, null, 4));
 3      else console.log(data);
 4  }

To be able to debug print method inside mymodule you'll have to place break-point in the main test.js script after line where you loaded you module for the first time (in this case on line 5). This is important because it will pause PhantomJS so PhantomJS will have enough time to inform VS Code that new module has just been dynamically loaded into PhantomJS. You'll also want to put some brake-point inside print method.

Clone this wiki locally