Comment by koito17

Comment by koito17 2 months ago

4 replies

In the case of Electron, there is a "main process" that is a Node.js process. This process has the capability to spawn "renderer processes", each browser window is a "renderer process". Through ipcMain and ipcRenderer, Node and Chromium have bidirectional comminication.

I don't think renderer processes run Node. Per the documentation,

  [C]ode ran in renderer processes should behave according to web standards ... [T]he renderer has no direct access to require or other Node.js APIs
https://www.electronjs.org/docs/latest/tutorial/process-mode...
killcoder 2 months ago

Renderers can access Node APIs via the ‘node integration’ setting or via a preload script.

  • themoonisachees 2 months ago

    Aren't these just IPCs disguised as normal function calls though? IIRC only the main node process does anything node, renderers can call "node functions" that really happen in the main process.

    • killcoder 2 months ago

      Not at all, in a renderer the Node and Chromium event loops are bound together, they’re part of the same v8 isolate, no IPC shenanigans.

      The main process really shouldn’t be used for anything except setup. Since it controls gpu paints amongst other things, blocking on it will cause visible stuttering and a bad user experience.

      https://www.electronjs.org/blog/electron-internals-node-inte...

notpushkin 2 months ago

> Renderer processes can be spawned with a full Node.js environment for ease of development. Historically, this used to be the default, but this feature was disabled for security reasons.

Makes sense.