On Electron, Node.js and processes
An electron works on the same principles as Node. In Node.js, threads are not an atomic unit of execution. You work in an event loop, and the default execution is async. See more details . Speaking of the fact that you can deploy several child processes in Node.js by marking them up.
Here is an example.
//forking a process using cluster var cluster = require('cluster'); var http = require('http'); var numCPUs = 4; if (cluster.isMaster) { for (var i = 0; i < numCPUs; i++) { cluster.fork(); } } else { http.createServer(function(req, res) { res.writeHead(200); res.end('process ' + process.pid + ' says hello!'); }).listen(8000); }
Credit How to create a Node.js cluster to speed up your applications. for example.
Electronic concepts
Returning to Electron, there are a couple of additional concepts you need to know about. The processes at Electron are unique in that they come in 2 flavors.
** Render Process ** - A process containing a web page. These processes are sandboxed, just like regular web pages.
** The main process ** is the process that loads your application. It creates rendering processes and their web pages. It can also act as a communication hub for all rendering processes rendering through rpc .
Here is part of the main.js sample from the Electronic Tutorial . This is the main process causing the browser window. Pay particular attention to the mainWindow variable.
'use strict'; const electron = require('electron'); const app = electron.app;
TL DR;
Threads do not exist in Node.js, and an electron is a wireframe built on Node.js \ io.js and Chromium. Electronic Foundation Node.js. You can create child processes with forking in Node.js.
source share