PhantomJS require() a relative path

Viewed 10836

In a PhantomJS script I would like to load a custom module but it seems relative paths do not works in PhantomJS ?

script.js:

var foo = require('./script/lib/foo.js');
foo.bar('hello world');
phantom.exit();

foo.js:

exports.bar = function(text){
  console.log(text);
}
  • According to fs.workingDirectory I am in the good directory
  • foo.js is not in the lookup path of phantomjs

Am I missing something ?

EDIT:

inject() is not revelant because I do not need to inject a JS to an HTML page but instead load my own module like require('fs') but with a relative path.

5 Answers
Related