In my nodeJS app, Im trying to build a helper library that connects to my external service.
I want to get to
const client = require('./myService')(serviceKey);
in the app I want to be able to call multiple functions, eg:
var healthcheckState = client.healthcheck();
var functionOneBool = client.someFunction('variable0','variable1');
I found several SO posts about how to do this; How to pass variables into NodeJS modules? How can I pass a variable while using `require` in node.js?
But I couldn't figure out how to adapt them.
This is myService.js
module.exports = function(serviceKey) {
var modules = {};
modules.healthcheck = {
function(){
console.log('I have a heartbeat!');
}
};
return modules;
};
When I try to run:
const client = require('./myService')('abc123');
client.healthcheck();
Im told that client.healthcheck is not a function
Where did I go wrong?