I am working on a node_module where I want to force users to pass in a string argument during require, like this:
const module = require('mymodule')('argument')
Then I have this on the module:
var someName = ''
module.exports = function (name) {
if (!name) console.log('Error!')
someName = name
console.log('Set someName: ' + someName)
}
So this works fine. However, when I try to require like this:
const module = require('mymodule')
And I added this:
module.exports = () => {
throw new Error('No name defined')
}
It doesn't go in there and no error is thrown.
How can I force users so that they will pass in an argument during require?
Thanks!