Last Updated: February 25, 2016
·
1.183K
· adamyanalunas

Check environment variables before node.js app starts

Sanity.js is a small library that checks a list of environment variables are set and meet your format requirements before your app starts up.

Here's a quick snippet of how it could be used:

var sanity = require('sanity');

sanity.check(['USER', 'MACHTYPE', 'INVISIBLE_FRIENDS', 'AREA_51']);

// Output if INVISIBLE_FRIENDS and AREA_51 are undefined
ERROR: Required settings are not correct!
  INVISIBLE_FRIENDS: undefined
  AREA_51: undefined

Full documentation (and tests!) are a the sanity repo.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside