I'm using FileCookieStore
which requires a path to a cookiefile and that this file is already created. I want to use fs.writeFile
to create this file if it does not already exist, but not to overwrite it if it does exist. However, in the implementation below, it overwrites the content of the cookiefile even if it exists, even though the wx
-flag should throw an error and not overwrite the file if it already exists.
var cookiePath = "cookie.json"
fs.writeFile(cookiePath, null, { flags: 'wx' }, function (err) {
if (err) throw err;
});
var j = request.jar(new FileCookieStore(cookiePath));
request = request.defaults({ jar : j });
function login(callback) {
// puts data into j which automatically writes the content to cookiePath
}
Have I misunderstood the proper use of writeFile
with the wx
-flag? If I run login()
the content of the cookie is automatically saved to cookie.json, but if I run the file again without calling login
, fs.writeFile
empties the cookiefile.
your code should be:
fs.writeFile(cookiePath, null, { flag: 'wx' }, function (err)
:)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With