Change directory in chaining fashion.
1. Reading .json file will strip comments and converte into JSON object. 2. Reading .js file is equivalent of require('dir/to/file') 3. Other files are just read. 4. Supply file as argument on last call. No chaning afterwards. 5. Module is syncro, but if you have good idea how to make it async please let me know.
var Cd = require('cd'); var cd = new Cd('.'); // Read lol.json from current directory var lol = cd('lol.json'); // Read wtf.js from test directory. var wtf = cd().test('wtf.js'); console.log('wtf:'+JSON.stringify(wtf)); // Chain as you like var file = cd().dir1().dir2(file_in_dir2);