UNPKG

get-express-starter

Version:

Get production ready express boilerplate with a single command

69 lines (63 loc) 2.49 kB
const dotenv = require('dotenv'); const path = require('path'); const Joi = require('joi'); dotenv.config({ path: path.join(__dirname, '../../.env') }); const envVarsSchema = Joi.object() .keys({ NODE_ENV: Joi.string().valid('production', 'development', 'test').required(), PORT: Joi.number().default(3000), MONGODB_URL: Joi.string().required().description('Mongo DB url'), JWT_SECRET: Joi.string().required().description('JWT secret key'), JWT_ACCESS_EXPIRATION_MINUTES: Joi.number().default(30).description('minutes after which access tokens expire'), JWT_REFRESH_EXPIRATION_DAYS: Joi.number().default(30).description('days after which refresh tokens expire'), JWT_RESET_PASSWORD_EXPIRATION_MINUTES: Joi.number() .default(10) .description('minutes after which reset password token expires'), JWT_VERIFY_EMAIL_EXPIRATION_MINUTES: Joi.number() .default(10) .description('minutes after which verify email token expires'), SMTP_HOST: Joi.string().description('server that will send the emails'), SMTP_PORT: Joi.number().description('port to connect to the email server'), SMTP_USERNAME: Joi.string().description('username for email server'), SMTP_PASSWORD: Joi.string().description('password for email server'), EMAIL_FROM: Joi.string().description('the from field in the emails sent by the app'), FRONTEND_URL: Joi.string().description('client app url'), }) .unknown(); const { value: envVars, error } = envVarsSchema.prefs({ errors: { label: 'key' } }).validate(process.env); if (error) { throw new Error(`Config validation error: ${error.message}`); } module.exports = { mode: envVars.NODE_ENV, port: envVars.PORT, mongoose: { url: envVars.MONGODB_URL, options: { useCreateIndex: true, useNewUrlParser: true, useUnifiedTopology: true, }, }, jwt: { secret: envVars.JWT_SECRET, accessExpirationMinutes: envVars.JWT_ACCESS_EXPIRATION_MINUTES, refreshExpirationDays: envVars.JWT_REFRESH_EXPIRATION_DAYS, resetPasswordExpirationMinutes: envVars.JWT_RESET_PASSWORD_EXPIRATION_MINUTES, verifyEmailExpirationMinutes: envVars.JWT_VERIFY_EMAIL_EXPIRATION_MINUTES, }, email: { smtp: { host: envVars.SMTP_HOST, port: envVars.SMTP_PORT, auth: { user: envVars.SMTP_USERNAME, pass: envVars.SMTP_PASSWORD, }, }, from: envVars.EMAIL_FROM, }, frontend: { url: envVars.FRONTEND_URL, }, };