2015-08-30 22:30:01 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								# Technical Differences Between Electron and NW.js (formerly node-webkit)
 
							 
						 
					
						
							
								
									
										
										
										
											2014-05-06 15:16:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-16 11:31:12 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								__Note: Electron was previously named Atom Shell.__
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								Like NW.js, Electron provides a platform to write desktop applications
							 
						 
					
						
							
								
									
										
										
										
											2015-08-30 22:30:01 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								with JavaScript and HTML and has Node integration to grant access to the low
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								level system from web pages.
							 
						 
					
						
							
								
									
										
										
										
											2014-05-06 15:16:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-05-06 09:52:24 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								But there are also fundamental differences between the two projects that make
							 
						 
					
						
							
								
									
										
										
										
											2015-04-16 11:31:12 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Electron a completely separate product from NW.js:
							 
						 
					
						
							
								
									
										
										
										
											2014-05-06 15:16:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-30 22:30:01 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								__1. Entry of Application__
							 
						 
					
						
							
								
									
										
										
										
											2014-05-06 15:16:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-30 22:30:01 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								In NW.js the main entry point of an application is a web page. You specify a
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								main page URL in the `package.json`  and it is opened in a browser window as
							 
						 
					
						
							
								
									
										
										
										
											2014-05-06 15:16:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								the application's main window.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-26 19:35:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								In Electron, the entry point is a JavaScript script. Instead of
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								providing a URL directly, you manually create a browser window and load
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								an HTML file using the API. You also need to listen to window events
							 
						 
					
						
							
								
									
										
										
										
											2014-05-06 15:16:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								to decide when to quit the application.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-26 19:35:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Electron works more like the Node.js runtime. Electron's APIs are lower level
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								so you can use it for browser testing in place of [PhantomJS ](http://phantomjs.org/ ).
							 
						 
					
						
							
								
									
										
										
										
											2014-05-06 15:16:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-30 22:30:01 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								__2. Build System__
							 
						 
					
						
							
								
									
										
										
										
											2014-05-06 15:16:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2017-05-10 13:42:21 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								In order to avoid the complexity of building all of Chromium, Electron uses [`libchromiumcontent` ](https://github.com/electron/libchromiumcontent ) to access
							 
						 
					
						
							
								
									
										
										
										
											2015-08-30 22:30:01 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Chromium's Content API. `libchromiumcontent`  is a single shared library that
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								includes the Chromium Content module and all of its dependencies. Users don't
							 
						 
					
						
							
								
									
										
										
										
											2015-04-16 11:31:12 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								need a powerful machine to build Electron.
							 
						 
					
						
							
								
									
										
										
										
											2014-05-06 15:16:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-08-30 22:30:01 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								__3. Node Integration__
							 
						 
					
						
							
								
									
										
										
										
											2014-05-06 15:16:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-03-12 01:54:59 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								In NW.js, the Node integration in web pages requires patching Chromium to
							 
						 
					
						
							
								
									
										
										
										
											2015-08-30 22:30:01 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								work, while in Electron we chose a different way to integrate the libuv loop
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								with each platform's message loop to avoid hacking Chromium. See the
							 
						 
					
						
							
								
									
										
										
										
											2015-11-17 11:47:57 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[`node_bindings` ][node-bindings] code for how that was done.
							 
						 
					
						
							
								
									
										
										
										
											2014-05-06 15:16:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-04-16 11:31:12 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								__4. Multi-context__
							 
						 
					
						
							
								
									
										
										
										
											2014-05-06 15:16:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2015-03-12 01:54:59 +05:30 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								If you are an experienced NW.js user, you should be familiar with the
							 
						 
					
						
							
								
									
										
										
										
											2015-04-26 19:35:52 -04:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								concept of Node context and web context. These concepts were invented because
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								of how NW.js was implemented.
							 
						 
					
						
							
								
									
										
										
										
											2014-05-06 15:16:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								By using the [multi-context ](http://strongloop.com/strongblog/whats-new-node-js-v0-12-multiple-context-execution/ )
							 
						 
					
						
							
								
									
										
										
										
											2015-04-16 11:31:12 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								feature of Node, Electron doesn't introduce a new JavaScript context in web
							 
						 
					
						
							
								
									
										
										
										
											2014-05-06 15:16:54 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								pages.
							 
						 
					
						
							
								
									
										
										
										
											2015-11-17 11:47:57 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-07-01 14:27:56 +09:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								Note: NW.js has optionally supported multi-context since 0.13.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2016-03-31 16:49:59 -07:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								[node-bindings]: https://github.com/electron/electron/tree/master/atom/common