Quitting app from node-main context #423

ubaltaci opened this Issue Feb 6, 2013 · 4 comments


None yet

3 participants

ubaltaci commented Feb 6, 2013


I looked https://groups.google.com/forum/?fromgroups=#!topic/node-webkit/R8d4cpCC-6o then when I try to quit app from node context; it throws reference error. Am I missed something ?

var gui = window.require('nw.gui');
ReferenceError: window is not defined

OS: OS X 10.8
NW version: 4.1
package-json: "node-main":"js/index",

zhchbin commented Feb 6, 2013

Hi, @ubaltaci requiring the 'nw.gui' directly didn't supported in the node-main. If you really want this, here is a workaround.
In the index.html(Which is specified in the main field of package.json), require the nw.gui and store it with process.mainModule.exports


  "name": "nw-test",
  "main": "index.html",
  "node-main": "foo.js"


   <script >
     process.mainModule.exports.gui = require('nw.gui');


exports.test = function () {

Now you can use it in the foo.js... Just a little trick, hope this will help. Anything wrong, please let me know.

ubaltaci commented Feb 6, 2013

thanks @zhchbin , I understand now and works like a charm. Thanks again.

@ubaltaci ubaltaci closed this Feb 6, 2013
darsain commented Feb 6, 2013

I'd like to reference issue #299 in here, as this is one of the reasons I've proposed it.

I just really don't like having anything.html file along with window property in package.json to be an app initiator. The current API is just not sufficient for a lot of complex apps and use cases.

ubaltaci commented Feb 6, 2013

I'm not an experienced javascript user ( or node.js ) but I have strong oop background especially in case of native mobile applications.

In my app; there are multiple windows and each one handles some data which initialized and processed in node-main file. Therefore; if nw.gui can reachable easily or without little tricks, manipulating life cycle of app become more easy. Also, again I'm noob on javascript, but my first impression on node-webkit's package.json , I've assumed there are two entry points for app ( index.html and main.js ) Even though it's kinda true if api structure changes as you proposed, I think node-webkit starters will feel more comfortable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment