0

I'm experimenting with Node-Webkit lately, if I call sth like that;

exports.name = function() {
    console.log('My name is Uğur');
};

Node-WebKit renderer throws a error:

"Uncaught ReferenceError: exports is not defined"

I couldn't understand, Is it caused by node-webkit or node.js itself. Since; 'node test.js' works without problem.

ubaltaci
  • 1,016
  • 1
  • 16
  • 27

1 Answers1

0

You need to run this in the Node's context (not WebKit's context). To do that, specify the script in 'node-main' in the manifest.

Here is an example:

index.js:

exports.callback0 = function (win) {
}

index.html:

<body onload="process.mainModule.exports.callback0(window)">

package.json:

{
  "name": "nw-demo",
  "node-main": "index.js",
  "main": "index.html"
}

HTH

Roger Wang
  • 1,388
  • 10
  • 8
  • thanks but I couldn't understand; we can call sth directly from webkit context like this; "var request = require('request')" , also node-webkit examples do that a lot. Is this special to exports ? – ubaltaci Jan 25 '13 at 23:07