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

Popular posts from this blog

.htaccess - First slash is removed after domain when entering a webpage in the browser -

Automatically create pages in phpfox -

c# - Farseer ContactListener is not working -