Skip to content

Check that environment variables are set before starting server

License

Notifications You must be signed in to change notification settings

sgreer81/express-env-check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Express Env Check

A simple package to check that required environment variables are set before starting server.

Usage

Add the following as early as possible in your main express start file (app.js or index.js).

const expressEnvCheck = require('express-env-check');

expressEnvCheck(
  ['DB_PASSWORD'], // A list of required environment variables
  ['DB_PASSWORD'] // A list of sensitive environment variables that should not have their values logged
);

The second argument is a list of sensitive environment variables that should not have their values logged. This is recommended for database passwords, api keys or other secrets.

See example.js for more detail.

Custom info / error handlers

Optionally, a custom info and error handler can be passed as function arguments. This can be useful if your app is using a custom logging service, or writing logs to a log file rather than the console. Below is an example.

const errorLog = (...args) => {
  console.error('custom error');
  console.error(...args);
};

checkEnvVars(['DB_PASSWORD'], ['DB_PASSWORD'], console.log, errorLog);

About

Check that environment variables are set before starting server

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published