Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including dotenv-parse-variables with all npm packages installed. Try it out:

var dotenvParseVariables = require("dotenv-parse-variables")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

dotenv-parse-variables v0.2.3

Parse dotenv files for Boolean, Array, and Number variable types, built for CrocodileJS


Slack Status NPM version Build Status Code Coverage Standard JS Style MIT License

Parse dotenv files for Boolean, Array, and Number variable types, built for CrocodileJS.



Imagine you have a configuration file at .env with the following:

# note how we use an asterisk here to turn off the parsing for this variable
# note how we use an asterisk in the array to turn off parsing for an array key value
# note a string between bacticks won't be parsed

After using this plugin, the environment variables are parsed to their proper types.

To test it out, simply log the returned object in your console:


And you'll see that it outputs the properly parsed variable types:

  // String
  FOO: 'bar',
  // Number
  BAZ: 2,
  // Boolean
  BEEP: false,
  // Array
  BOOP: [ 'some', 'thing', 'that', 'goes', 'wow' ],
  // NOTE: this was not parsed due to the * asterisk override above
  BLEEP: 'false',
  // NOTE: only the `true*` above was opted out through the use of an asterisk
  PING: [ 'ping', 'true', 2, 100 ],
  // NOTE: this was not parsed because the string was between bacticks
  PONG: 'some,thing,that,goes,wow'

If your configuration line ends in * it will not be parsed by this package, which allows you to keep values as the String variable type if needed. Also when you encapsulate a value between bacticks e.g. `value`, the value won't be parsed and it will return as a String variable. This can be used in situations where you for example have a ',' inside your string and it should not be parsed as an array.


npm install --save dotenv-parse-variables


This package works just fine with dotenv, however we also recommend to use dotenv-extended and dotenv-expand as we do in CrocodileJS.

Example with dotenv:

const dotenv = require('dotenv');
const dotenvParseVariables = require('dotenv-parse-variables');

let env = dotenv.config({})
if (env.error) throw env.error;
env = dotenvParseVariables(env.parsed);


Example with dotenv-extended (which supports a well-defined .env file) and dotenv-expand (which supports variable interpolation):

const dotenvExtended = require('dotenv-extended');
const dotenvMustache = require('dotenv-mustache');
const dotenvParseVariables = require('dotenv-parse-variables');

let env = dotenvExtended.load({
  silent: false,
  errorOnMissing: true,
  errorOnExtra: true
env = dotenvMustache(env);
env = dotenvParseVariables(env);


If you don't want to use this package to parse variable types, you could also use getenv (but it requires more work).



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free