Can't use app module in render process


#1

I have var app = require('app'); in my render process but I keep getting this error “Uncaught Error: Cannot find module ‘app’”.

Is the app module available in the render process or is it limited to only being used in the main process?

The reason I am using the app module is because I want to use app.getPath(userData); so I can work with my config file. I read Electron App Database File Structure/Code Structure and it looks like I should be trying to keep as much out of the main process as possible. Maybe I am missing something?


#2

According to the documentation here:

app is only available to the main process.


#3

Makes sense from a security standpoint.

Thanks for the quick response!


#4

You can use the remote module like so:

var remote = require('remote')
var app = remote.require('app')

#5

Now you have to do:

const {app} = require('electron')
const {BrowserWindow} = require('electron')

#6

const {app} = require(‘electron’).remote;
var userDataPath = app.getPath(‘userData’);

// Example userDataPath: “/Users/name/Library/Application Support/Electron”