sendgrid-mail
Version:
The easiest way to send mail with sendgrid.
25 lines (20 loc) • 625 B
JavaScript
const fs = require('fs')
const debug = require('debug')('sendgrid-mail:config')
const dotenv = require('dotenv')
const setConfig = async (filename) => {
debug(`setting configuration from ${filename}`)
try {
const envconfig = dotenv.parse(await fs.promises.readFile(filename))
for (const k in envconfig) {
if (!process.env[k]) {
debug(`setting ${k}=${envconfig[k]}`)
process.env[k] = envconfig[k]
} else {
debug(`not setting ${k}... already set to ${process.env[k]}`)
}
}
} catch (err) {
debug(`can't read file ${filename}`)
}
}
module.exports = setConfig