Reputation: 40084
I have an npm module that I would like to configure once and call in multiple places.
The npm module (let's call it 'signature') is basically like this
module.exports = function(options) {
return new Signature(options);
};
var Signature = function(options) { }
Signature.prototype.sign = function() {}
I made another module ('signer') to configure it:
var signature = require('signature');
module.exports = function() {
// I pass whatever config options here
return signature({});
};
In my code I do:
var signer = require('../utils/signer');
signer.sign();
However this gives me a "has no method "sign" error. What am I doing wrong? I suspect I have to initialize something but not sure what. If I bypass the config module (signer) and just call the signature module then it works fine:
var signature = require('signature');
var s = signature();
s.sign();
Upvotes: 1
Views: 5573
Reputation: 12441
Signer exports a function that returns a signature. Try:
var signer = require('../utils/signer');
signer().sign();
Upvotes: 1