How to move express-mailer config to separated file?

276
June 22, 2017, at 09:36 AM

In doc of this npm package: https://www.npmjs.com/package/express-mailer

Config must be in app.js file:

// project/app.js 
var app = require('express')(),
    mailer = require('express-mailer');
mailer.extend(app, {
  from: 'no-reply@example.com',
  host: 'smtp.gmail.com', // hostname 
  secureConnection: true, // use SSL 
  port: 465, // port for secure SMTP 
  transportMethod: 'SMTP', // default is SMTP. Accepts anything that nodemailer accepts 
  auth: {
    user: 'gmail.user@gmail.com',
    pass: 'userpass'
  }
});

But I have this structure:

app_dir
   config_dir
       mail.js
   app.js

And need to put this block in mail.js

It's possible to do that?

Thanks

Answer 1

Using js config (what you want)

// project/config_dir/mail.js
module.exports = {
  from: 'no-reply@example.com',
  host: 'smtp.gmail.com', // hostname 
  secureConnection: true, // use SSL 
  port: 465, // port for secure SMTP 
  transportMethod: 'SMTP', // default is SMTP. Accepts anything that nodemailer accepts 
  auth: {
    user: 'gmail.user@gmail.com',
    pass: 'userpass'
  }
} 
// project/app.js 
var app = require('express')(),
    mail_config = require('./config_dir/mail');
    mailer = require('express-mailer');
mailer.extend(app, mail_config);

Using json config

// project/config_dir/mail.json
{
  from: "no-reply@example.com",
  host: "smtp.gmail.com",
  secureConnection: true,
  port: 465,
  transportMethod: "SMTP",
  auth: {
    user: "gmail.user@gmail.com",
    pass: "userpass"
  }
} 
// project/app.js 
var app = require('express')(),
    mail_config = require('./config_dir/mail.json');
    mailer = require('express-mailer');
mailer.extend(app, mail_config);
Rent Charter Buses Company
READ ALSO
Github use webook to automatically update cloned repo on remote server

Github use webook to automatically update cloned repo on remote server

My team is constantly adding json objects to a git repo that describe current projects they are working on/ have completedI developed a very simple api on a remote server that I can send these objects to, populate a list held in memory, and then make it possible...

252
How to convert to best prefix using js-quantities?

How to convert to best prefix using js-quantities?

I have a value of `1200000 mm' and I wan't to have a method which automatically transfers to the best prefix like:

324
OAuth2, Using POST and Yet… Method Not Allowed?

OAuth2, Using POST and Yet… Method Not Allowed?

Basically I'm trying to create a website that requires interfacing with the Discord API to retrieve user information to work

321