node.js - path.join does not work? -


i want read path , wrote 2 different codes.the first code not work second code works perfectly. not understand differences. can explain me going on? thanks. file stored in /modules/config/

first code:

var tmpmodulepath = path.join('./modules/',"config/"); var moduleconfiginfo = require(tmpmodulepath + "_test.js"); 

second code:

var tmpmodulepath = path.join('./modules/',"config/"); var moduleconfiginfo = require("./" + tmpmodulepath + "_test.js"); 

from first code, error: can not find module ..._tset.csv

if console.log generated path results:

first code block:

"modules/config/_test.js"

second code block:

"./modules/config/_test.js"

in second case, have relative path starting current directory (./). require modules folder starting current directory.

in first case, path absolute, meaning require modules folder starting root path of filesystem.

i hope understand difference now.

what want use in case path.resolve:

var tmpmodulepath1 = path.resolve('./', 'modules/',"config/", 'test.js'); 

check answer this question understand difference between .join , .resolve.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -