I have two files: a.js and b.js.
a.js:
console.log(require("./b.js")());
module.exports = function () {
console.log("Hello Mars!");
};
b.js:
module.exports = function () {
console.log("Hello World");
};
By bundling these files I obtain c.js:
browserify a.js -o c.js
I expect c.js to export a function (that prints Hello Mars when called). By requireing c.js in a node process I get an empty object.
$ node
> c = require("./c.js")
Hello World
undefined
{}
> c()
TypeError: c is not a function
at repl:1:1
at REPLServer.defaultEval (repl.js:252:27)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer.<anonymous> (repl.js:417:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:210:10)
at REPLServer.Interface._line (readline.js:549:8)
at REPLServer.Interface._ttyWrite (readline.js:826:14)
Since node has already a module object, how can I tell Browserify to use this module object for the main file, so I will get the Hello Mars function in the module.exports when using require in Node?
I checked out the docs, but I didn't find any option... Maybe I miss something.
I just want to bundle a module (that has dependencies) and require it in a node process.