Reputation: 1373
So this question extends this one here after figuring out what was happening i need to know if it's a bug I'm using node.js v4.1.0 on Debian and to solve my issue i was having with fs.writeFile i had to put the full path e.i /apps/json.json for it to actually save it where i wanted it to be but using ./json.json would save it to the /root instead of where my server.js file resided but how come when using require("./json.json") it works correctly and grabs the file relative to where the server.js is e.i /apps/server.js. Is this a know issue?
Upvotes: 0
Views: 99
Reputation: 887453
You're confusing the current directory with the directory containing your script.
All fs
APIs resolve paths relative to the current directory, which may be anything.
require()
, by contrast, ignores the current directory entirely and resolves paths based on the directory containing the JS file.
Upvotes: 1