Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Electron app how do you reference the temp path?

Learning Electron I'd like to do some file processing after a drag and drop. On a Mac the equivalent for tmp is a $TMPDIR. Referencing the API documentation of app I was able to locate the app.getAppPath() which shows my path from a simple console log from main.js. Below app.getAppPath() there is getPath() but when I try app.getPath(temp):

let foobar = app.getAppPath("temp")
console.log(foobar)

I get an error in the console of:

ReferenceError: temp is not defined

Through my research I've read:

  • How to store user data in Electron
  • How to get the original path of a portable Electron app?
  • Creating and Using Temporary Files
  • Get Special folder Path in Electron
  • electron temp directory
  • How to set a custom path for Electron app installer

In Electron is there a built-in for the temp directory to work on all operating systems or a process to reference?

Note:

Even after referencing the string of:

console.log(`The temp path is: ${app.getAppPath("temp")}`)

it returns the same response as:

console.log(`The AppPath is: ${app.getAppPath()}`)

which is:

The temp path is: /Users/Grim/Documents/GitHub/electron-quick-start-boilerplate
The AppPath is: /Users/Grim/Documents/GitHub/electron-quick-start-boilerplate

and the above console.log tests have been added after letWindow.

like image 317
DᴀʀᴛʜVᴀᴅᴇʀ Avatar asked Mar 05 '19 14:03

DᴀʀᴛʜVᴀᴅᴇʀ


1 Answers

app.getAppPath() doesn't take an argument.

For app.getPath(name), the argument should be the string "temp": app.getPath("temp").

like image 159
Stock Overflaw Avatar answered Nov 15 '22 03:11

Stock Overflaw