Skip to content

Instantly share code, notes, and snippets.

@rla
Created February 19, 2018 11:54
Show Gist options
  • Save rla/a781e56df772713d92b55957f526d16b to your computer and use it in GitHub Desktop.
Save rla/a781e56df772713d92b55957f526d16b to your computer and use it in GitHub Desktop.
Node.js Express config file pattern
const config = require('../config.json');
module.exports = config;
{
"port": 8020,
"self": "http://localhost:8020",
"session": {
"key": "xxx"
},
"db": {
"host": "127.0.0.1",
"database": "xxx",
"user": "xxx",
"password": "xxx"
},
"timezone": "Europe/Tallinn",
"mail": {
"from": "noreply@xxx",
"smtp": {
"port": 25,
"host": "xxx"
}
}
}
const util = require('util');
const nodemailer = require('nodemailer');
const config = require('../config');
const transport = nodemailer.createTransport(config.mail.smtp);
// Sends mail. Wrapped into a promise.
const sendMail = util.promisify((options, cb) =>
transport.sendMail(options, cb));
exports.send = sendMail;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment