cocycles / electron-storage Goto Github PK
View Code? Open in Web Editor NEWSimply save/load json files to/from file system in electron applications
License: MIT License
Simply save/load json files to/from file system in electron applications
License: MIT License
Hi, where is file created on MacOSX if no path is specified?
I am searching it after i set() it but i can't actually find it....
thanks
I have the following code.
` var filePath = "Settings.json"
storage.set(filePath, "{'balance': 1000.21, 'num':100, 'is_vip':true, 'name':'foo'}")
.then(data => {
console.log(data);
})
.catch(err => {
console.error(err);
});
storage.get(filePath, (err, data) => {
if (err) {
console.error(err)
} else {
console.log(data);
}
});`
The data is written to the Settings.json under C:\Users\thardes2\AppData\Roaming\MyApp, but when I try to get them with the get function I get the following error:
The file in path C:\Users\thardes2\AppData\Roaming\MyApp/Settings.json is not a valid json file
So the format of the path is wrong. As you can see, I am just using the example provided in the README.
Any idea or solution to this?
Thank you :-)
why are filePaths joined to "userData" folder?
is it possible to avoid this and save, or load a file from, for example, the user's Desktop? or a custom-defined path relative to the filesystem root?
return path.join(userData, filePath);
Thanks!
https://github.com/jviotti/electron-json-storage has a few more functionalities, like has, keys and clear.
Both are great projects, though similar!
Perhaps if filePath
is an absolute user directory then it would just write to that folder. e.g..
storage.get('/Users/dave/sites/my-site/config.json')
What do you think about this idea?
Hi there. I get this error on macOS.
var data = new Object();
data.name = name;
data.address = address;
storage.set('customers.json', data)
.then(() => {
console.log('Data saved successfully!')
})
.catch((err) => {
console.log(err);
});
It writes to the file but then when I use the get function,
var oldData = storage.get('customers.json')
.then(d => {
console.log(d);
})
.catch(err => {
console.log(err);
});
It gives me that the error.
And here is what the console gives:
Error: The file in path /Users/syncster31/Library/Application Support/ASMS/customers.json is not a valid json file
at /Users/syncster31/Documents/Programming/Electron/my-app/node_modules/electron-storage/dist/index…:37
at tryToString (fs.js:449)
at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:436)
I noticed when trying to use isPathExists
, it requires adding the .json
to the path name unlike the set
and get
methods. I'm assuming that's on purpose but it doesn't seem consistent with the other methods.
Maybe that should be clarified in the README?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.