node.js - File paths in nodejs -


i'm trying read file relative path in nodejs using:

readfile.js

var path = require('path'); var file_path = path.join(__dirname, "relativedir", "file.conf"); 

which in directory layout such as:

/home/user/project/readfile.js /home/user/project/relativedir/file.conf 

produces following file path.

/home/user/project/home/user/project/relativedir/file.conf 

why?

i tried omitting __dirname variable in join() give path:

relativedir/file.conf 

i've tried using relative path of relativedir join outputs same path:

var path = require('path'); var file_path = path.join("./relativedir", "file.conf"); 

edit:

i following error message:

fs.js:640   return binding.open(pathmodule._makelong(path), stringtoflags(flags), mode);                  ^  error: enoent: no such file or directory, open /home/user/project/home/user/project/relativedir/file.conf 


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -