#How to use function before initializing within module.exports
20 messages · Page 1 of 1 (latest)
have you tried putting checkEmailExists at the beginning of module.exports?
Yup that didn't work
that doesn't work, scoping will break
What should i do ?
you would need to have the functions declared outside and then just add them to the exports object as shorthand
well, only checkEmailExists needs to be outside, but it's better to just go all the way
yea +1. I thought about that but I wasn't sure about this
I thought i was shortcutting by declaring inside the exporting
for future reference, for methods in an object you'd need this. to access other methods (or properties) of the same object
but that link will be broken when it's destructured in the export
so this would be the safer way
shortcuts don't always work
is doing it in a class better ? will it solve the issue ? or it is even good to have services as a class
probably not strictly better, they'd have their advantages and drawbacks
i don't see any reason to really turn this into a class.
actually come to think of it, doing module.exports.register might work
but i've never seen that used, i guess it either doesn't work or it's too ugly in comparison
or referencing an object that is then assigned to module.exports
I think declaring then exporting is the choice
but this is the more commonly used pattern as far as ive seen, so i still think this is the safer way