Skip to content Skip to sidebar Skip to footer

What Does It Mean For Electron To Combine Node.js And Chromium Contexts?

In a blog post the author mentions that Electron combines Node and Chromium into a 'single context' which implies that we don't have to use Browserify to transform code. I understa

Solution 1:

Chromium is a Webkit based web browser with the V8 javascript engine. It supports all the usual browser and DOM APIs and thus is good for making web pages and not good at interacting with the underlying system.

Node.js was built by striping out the V8 engine, making a headless command line application, and adding extensive APIs to access the file system, require() other files, run other shell programs, etc. (things you'd expect of a true scripting language.

Electron in a simplified way is an attempt to replace the V8 engine used in Chromium with the new more general purpose oriented one of Node.js. It exposes a few extra APIs to node.js to allow for opening chromium windows, but also every chromium window using a <script> tag will interpret it with the node.js engine.

Why Electron? The reason that Chromium can't do this by itself is because it was originally designed to be a web browser and in web browsers file system APIs would be unheard of as typically files are hosted on a remote server and accessing files on a user's computer would be a security risk (because why should any single webpage have access to all your files?).

require statements now work out of the box because node.js has filesystem support will allows them to be synchronously read from the disk without the need for bundling them into the same javascript file or requesting them from a server.


Post a Comment for "What Does It Mean For Electron To Combine Node.js And Chromium Contexts?"