0

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
1
  • replace module2.run(); with module2().run(); Commented Aug 24, 2016 at 9:39

1 Answer 1

1

try this

var module2 = require('moduleBase)();

module2.run();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.