Using NW.js' main module
As we stated in the first chapter, NW.js checks for the main
field in the manifest file in order to load the given file when opening the application's first window. The node-main
field acts similarly, but instead of referring to an HTML file, it will allow you to set a main Node.js module, which will run in the background through the application's life cycle independently of the window context (even though it will quit by default when all the application windows are closed).
In the previous chapter, we've seen that we can use process.mainModule
from the window context in order to get the main module, but more specifically, besides global
, we can take advantage of process.mainModule.exports
to share objects between the two contexts.
Tip
Thanks to the global
object, the window
object is also shared with the main module, but you can't obviously access it until a ready signal is sent from the DOM.
Let's see an example:
package.json:
{ "name": "secondsSinceStart", "node...