Reputation: 11
I was using fs to write values from textarea into a file and had issues with the path until I found on stackoverflow that the path has to be a tmp folder. I did that and the terminal shows the function was successful but now I don't know where that folder is and how I can access.
app.post('/scheduleTweet', function (req, res) {
fs.writeFile('/tmp/scheduleTweet', req.body.text, err => {
if (err) {
console.error(err);
} else{
console.log("success");
}
});
})
Can somebody help me please? I'm self taught so not really sure what to google even.
Upvotes: 1
Views: 942
Reputation: 16728
If the path starts with a /
, then fs.writeFile
writes to that path on the current drive, for example, to C:/tmp/schedule.txt
. Otherwise, it writes relative to the current working directory of the node process. It's easier if you make it relative to the directory containing your Javascript code: fs.writeFile(__dirname + "/tmp/schedule.txt", ...)
.
Upvotes: 2