#How to use function before initializing within module.exports

20 messages · Page 1 of 1 (latest)

red needle
#

How do I use emailExists function in the register function

young isle
#

have you tried putting checkEmailExists at the beginning of module.exports?

simple atlas
#

that doesn't work, scoping will break

red needle
simple atlas
#

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

young isle
#

yea +1. I thought about that but I wasn't sure about this

red needle
simple atlas
#

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

simple atlas
simple atlas
red needle
#

is doing it in a class better ? will it solve the issue ? or it is even good to have services as a class

simple atlas
#

probably not strictly better, they'd have their advantages and drawbacks

#

i don't see any reason to really turn this into a class.

simple atlas
#

or referencing an object that is then assigned to module.exports

red needle
#

I think declaring then exporting is the choice

simple atlas