jeudi 26 mars 2015

Should i always call a module into a var or execute immediately in node

So, i am coming from a LAMP stack and all this new js is quite new to me.


I have written an email sending module for my little app which is executed as follows:



var emailer = require( '../../app/emailer.js');
emailer({
tplName : 'activationEmail',
tplVariables : {name:'john',activationLink:'bob'},
sendToEmail: 'john@gmail.com',
sendToName: 'John',
fromEmail : 'noReply',
subject: 'Activation email'
});


Now this works just fine however i am not sure what is better (as i am missing some fundamental nodejs knowledge), to run as above or run as this:



require( '../../app/emailer.js')({
tplName : 'activationEmail',
tplVariables : {name:'john',activationLink:'bob'},
sendToEmail: 'john@gmail.com',
sendToName: 'John',
fromEmail : 'noReply',
subject: 'Activation email'
});


As you can see here this is triggereing an activation email, the emailer module is being called from within a passport module.


My question, should I 'require' the module into a var then reference the var later, or require the emailer module each time i need it.. i'm not sure what the difference is..


A NooB Q i know, but i can't find a solid answer on google.


Thanks in advance, John


Aucun commentaire:

Enregistrer un commentaire