Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

There is a technical .js between Electron and NW (formerly node-webkit).


May 25, 2021 Electron



Note: Electron's original name is Atom Shell.

Similar to the NW .js, Electron provides a platform to create desktop apps with JavaScript and HTML, while integrating Node to grant Web pages access to the underlying system.

But there is also a fundamental difference between the two projects, making Electron and NW .js two separate products.

1. The entrance to the app

In NW .js, the main portal of an app is a page. You package.json which opens as the app's main window.

In Electron, the portal is a JavaScript script. B etween providing a URL directly, you need to manually create a browser window and then load html files through the API. You can also listen for window events and decide when to let your app exit.

Electron works more like node .js runtime. Electron's APIs are more underlying, so you can use it instead of PhantomJS for browser testing.

2. Build the system

To avoid the complexity of building the entire Chromium, libchromiumcontent Content API through libchromiumcontent. libchromiumcontent a separate shared library that introduces the Chromium Content module and all of its dependencies. Users do not need a powerful machine to build Electron.

3. Node integration

In the NW .js, Node integration in web pages needs to be achieved by patching Chromium. B ut in Electron, we chose another approach: integrating the message loop with libuv through each platform, avoiding making changes directly on Chromium. You can node_bindings see how this is done.

4. Multi-context

If you are an experienced NW .js, you should be familiar with the concepts of node context and web context. These concepts are derived from the way NW .js implementation of the NW system.

By using Node's multi-context attribute, Electron does not need to introduce a new JavaScript context into a Web page.