Reputation: 264
I'm trying to make my script write a file to the root directory instead of the module directory
const fs = require("fs");
const path = require("path");
fs.writeFileSync(path.join(__dirname, dir, "file.txt"), this.config);
but no matter what I try it makes it in the module directory.
Upvotes: 1
Views: 1735
Reputation: 11973
If you run your program from your root directory (the root of your project folder?), you might want to use process.cwd()
:
fs.writeFileSync(path.join(process.cwd(), "file.txt"), this.config);
Upvotes: 2