I have a mail service class set up on an express server.
What is the recommended method for creating a transport?
class mailService {
private transport: nodemailer.Transport;
constructor(){
this.transport = nodemailer.createTransport('configstring');
}
public sendEmail(email: string){
//send email
}
}
OR
class mailService {
public sendEmail(email: string){
let transporter = nodemailer.createTransport('configstring');
//send email
}
public sendOtherEmail(email: string){
let transporter = nodemailer.createTransport('configstring');
//send email
}
}
The documentation mentions "You can reuse a transport as often as you like after creating it," leading me to consider that the first option might be better, although I am unsure if there are any advantages to it.
Would repeatedly creating the transport be problematic due to repetition or could it result in multiple instances lingering in memory every time the sendEmail
function is called?