I am using Fuse to develop a new version of my app ‘contractnotify’. The UI is ready and i am now hooking up our API. Everything is working so far. I login making a POST request. I get a token back. This all works fine. Problem is when i try to write the token (or anything else) to a file called filedb.txt nothing happends. I am working on a mac so i first thought it had to do with file permissions, but i put everything on read/write and still no luck. Maybe my code is wrong, please advise. Thank you!
My code:
var Observable = require("FuseJS/Observable");var requestObject = {'username':'myusername', 'password':'mypassword'};
fetch('https://www.contractnotify.com/api/login', {
method: 'POST',
headers: { "Content-type": "application/json"},
dataType: 'json',
body: JSON.stringify(requestObject)
}).then(function(response) {
status = response.status; // Get the HTTP status code
response_ok = response.ok; // Is response.status in the 200-range?
return response.json(); // This returns a promise
}).then(function(responseObject) {
// Do something with the result
console.log("Success"); //this works i get a success
var thetoken = responseObject.token; // this is the token i get
console.log(thetoken); //this shows the token and works
var storage = require('FuseJS/Storage'); //require storage
storage.write("/filedb.txt", thetoken); //write to file
}).catch(function(err) {
// An error occured parsing Json
console.log("error", status);
});
This will give you an indication of whether the operation failed or succeeded.
I would try removing the leading slash / from the filename, I think that could easily be the problem. Fuse currently stores files at the strangest locations on Windows by default, and it wouldn’t surprise me if trying to force an absolute path on Mac would cause it to fail.
Thank you for your reply. You understood correctly. Strange enough LOG result is ‘Stored file’, but there is nothing written to the file. I searched for filedb.txt on my mac (to check it was maybe stored somewhere else) but there is only the one i added and it’s empty. Any additional ideas? Thanks again!
Hey @Bjorn. Thank you for your reply. It was up to me I guess. I thought the file will be saved in project directory and I haven’t seen any details of the saved file location on API page. I’ve just cheked and the file is there and it’s written properly.
One note, the same directory for Windows is located @ %AppData%\Local.