user6171746
user6171746

Reputation:

Module export modules not working

I have the following code which need to export module based of some condition,

moduleBase.js
var spawnLinux = require('child-process').spawn;
var module2 = require('module_2');

var isWin = process.platform === 'win32';

module.exports = function spawn() {
    if (isWin) {
        return module_2;
    } else {
        return spawnLinux;
    }
};

The problem is that module_2 is returning error when used by external module but if it used inside this specific module it runs OK, what can be the problem in the export?

If I use it like this (in diffrent module)

var module2 = require('module_2');

module2.run(); //this working

this is not working

var module2 = require('moduleBase);

module2.run();//Here I got error

Upvotes: 0

Views: 771

Answers (1)

Amin Cheloh
Amin Cheloh

Reputation: 475

try this

var module2 = require('moduleBase)();

module2.run();

Upvotes: 1

Related Questions