Answer the question
In order to leave comments, you need to log in
How to specify path to save file to nodejs desktop?
I create an application on electron.js through a node, I need to save the file on the desktop, I need to find out the path to the desktop. Those. a person presses a button in the application, and automatically the file is saved to the desktop.
var fio = {
data: []
};
fio.data.push({
name: crypt.encrypt(name),
group: crypt.encrypt(group)
});
var json = JSON.stringify(fio);
if(!fs.existsSync('data.json')) {
fs.writeFile('data.json', json, 'utf8');
} else {
fs.unlink('data.json', function (err) {
if(err) return console.log("Не удалось удалить файл");
fs.writeFile('data.json', json, 'utf8');
console.log('Файл записан')
})
}
Answer the question
In order to leave comments, you need to log in
Pull the native code, if you are too lazy to deal with your native module, then the easiest way is to take
https://www.npmjs.com/package/ffi
+
https://stackoverflow.com/questions/17933917/get-t...
https://electronjs.org/docs/api/app#appgetpathname
import {app} from 'electron';
console.log(app.getPath('desktop'));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question