W
W
websjunior2018-04-30 18:13:02
Node.js
websjunior, 2018-04-30 18:13:02

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

2 answer(s)
A
Alexander Taratin, 2018-04-30
@Taraflex

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...

D
Dmitry Belyaev, 2018-04-30
@bingo347

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 question

Ask a Question

731 491 924 answers to any question