Check out a free preview of the full Electron Fundamentals, v2 course:
The "Remote Module" Lesson is part of the full, Electron Fundamentals, v2 course featured in this preview video. Here's what you'd learn in this lesson:

Steve demonstrates how to utilize the remote module in the renderer process to "talk" to the main process.

Get Unlimited Access Now

Transcript from the "Remote Module" Lesson

>> Steve Kinney: Here's a problem. Opening a file, we got it totally working in the main process. The main process is totally separated from the renderer process, right? So it's very cool that we can open up a file there, but we need to somehow facilitate the communication between the two processes.

[00:00:20] So let's actually look at another module in Electron. This one's called the remote module. And it remote is only available in the renderer process, and it's a way to talk to the main process, right? So I could say something along the lines of, let's actually biggerize that font

>> Steve Kinney: That's the technical term.
>> Steve Kinney: So require('electron').remote.
>> Steve Kinney: And you can see that remote's got a few things that it has at its disposal. It actually has a lot of the stuff that we saw in the renderer process. So BrowserWindow, right? There's no reason that a renderer process, a renderer process in of itself cannot create another render a process, only the main process can do that.

[00:01:08] But remote is a proxy back to the main process, right? So anything that's available in the main process, a renderer process can't do it itself and be like, hey, main process, can you do me a solid and do that thing for me? And the main process is like, yeah, I'll do that for you.

[00:01:24] The one that we care about is require, right? Because it will just talk to the main process itself, not main.js, right? So we can actually say, okay, main process, go read that main.js file for me. So we can say,
>> Steve Kinney: main.js, we'll actually call this one mainProcess.
>> Steve Kinney: And mainProcess is right now an empty object, right?

[00:02:04] Because in Node we export things from a file, right? There is a module.exports object. By default, module.exports is an empty object, which makes sense about when we go ahead and we require it. So what we might consider doing is instead of getFilesFromUser, we'll say exports.get file from user, right?

[00:02:26] So we'll take that empty object, we'll put a property on it, a method on it, called getFileFromUser.
>> Steve Kinney: Cancel this. Start it back up.
>> Steve Kinney: Now we'll do remote = require('electron').remote
>> Steve Kinney: We'll call this one mainProcess again.
>> Steve Kinney: And you can see I've got this getFileFromUser, right? So we require the remote module in the renderer process.

[00:03:08] We use remote.require to grab that main process file where we're exporting getFileFromUser. So I could say something along the lines of mainProcess.getfilefromuser.
>> Steve Kinney: And we can trigger it from the renderer process.