I have project
A
config.json
B.setConfig('./config.json')
B.setConfig(path)
fs.existsSync(path)
require(path)
Cannot find module "./config.json"
B
require
setConfig
I found it, eventually, that if we want to take a relative path from module A
(call it remotePath
), and use it within require
in module B
, then to get the full path inside module B
we can use the following:
var path = require('path');
var fullPath = path.join(path.dirname(process.argv[1]), remotePath);
var moduleInsideA = require(localPath); // this now works
process.argv[1]
gives us the module A
start-up file, from which we take the directory path, and then join it with the remote relative path, which then gives us the full path.