Safely store the nodemailer password

I have an application that sends mail using nodemailer .

transporter = nodemailer.createTransport({
  service: 'Gmail',
  auth: {
    user: "email",
    pass: "what here?"
  }
});

      

I want to keep the open app in the app, just for it (along with no plain text password anywhere).

I know about nodemailler-direct, but is there a better option here? I also thought about asking the server console for a password, but this is inconvenient.

Is there a "correct" or standard way to do such a thing?

+3


source to share


1 answer


Use environment variables:

transporter = nodemailer.createTransport({
  service: process.env.NODEMAILER_SERVICE,
  auth: {
    user: process.env.NODEMAILER_USER,
    pass: process.env.NODEMAILER_PASS
  }
});

      



You can set these variables on the server and the application will pick them up. For example:

NODEMAILER_SERVICE="Gmail"

      

+5


source







All Articles