javascript - Why do require and fs.existSync use different relative paths -
i have code here:
if(fs.existssync('./example/example.js')){ cb(require('../example/example.js')); }else{ cb(); } why should fs.existsync using different directory require?
this directory tree excluding things not needed... (i using express btw)
\example example.js \routes index.js <-- 1 using code app.js <-- 1 requires index.js , calls functions using app.get('/example',example.index);
the path use require relative file in call require (so relative routes/index.js); path use fs.existssync() (and other fs functions) relative current working directory (which directory current when started node, provided app doesn't execute fs.chdir change it).
as reason of difference, can guess, require mechanism 'extra' logic w.r.t. finding other modules makes sense. should not influenced runtime changes in application, aforementioned fs.chdir.
Comments
Post a Comment