DotEnv

DotEnv

Source:

DotEnv-like module for WSH (Windows Script Host) that reads/writes environment values in a .env file.

Requires

Members

(static, constant) envPathDefault :string

Source:

The path of .env directory in the current directory.

Type:
  • string

(static, constant) envPathPortable :string

Source:

The path of .env directory in the directory of WSH script which is specified 1st argument by wscript.exe or cscript.exe.

Type:
  • string

(static, constant) envPathUsers :string

Source:

The path of .env directory in the user's directory (%USERPROFILE%). Ex. C:\Users<Name>.env

Type:
  • string

Methods

(static) config(optionsopt) → {object}

Source:

Stores the values in .env file to process.env

Examples
// If the contents of .env file are following...
// # Lines beginning with # are threated as comments,
// EMPTY=
// JSON={ foo: "bar" }
// WHITE_SPACE=  some value
// SINGLE_QUOTE='  some value '
// DOUBLE_QUOTE="  Some Value "
// MULTILINE="new
// line"
// DIR_7ZIP=C:\Program Files\7-Zip
// PATH_CONFIG=.\.config\office-smb-resources.json
var dotenv = Wsh.DotEnv;
dotenv.config();

// Ex.1
console.dir(process.env);
// Outputs: {
//   ..
//   ...
//   EMPTY: '',
//   JSON: { foo: "bar" },
//   WHITE_SPACE: 'some value',
//   SINGLE_QUOTE: '  some value ',
//   DOUBLE_QUOTE: '  Some Value ',
//   MULTILINE: 'new\nline',
//   DIR_7ZIP: 'C:\\Program Files\\7-Zip',
//   PATH_CONFIG: '.\\.config\\office-smb-resources.json' }
// Ex.2 Failed to read .env file
var dotenv = Wsh.DotEnv;
var result = dotenv.config();

if (result.error) throw result.error

console.dir(result.parsed);
// Outputs: {
//   EMPTY: '',
//   JSON: { foo: "bar" },
//   WHITE_SPACE: 'some value',
//   SINGLE_QUOTE: '  some value ',
//   DOUBLE_QUOTE: '  Some Value ',
//   MULTILINE: 'new\nline',
//   DIR_7ZIP: 'C:\\Program Files\\7-Zip',
//   PATH_CONFIG: '.\\.config\\office-smb-resources.json' }
Parameters:
Name Type Attributes Description
options object <optional>

Optional parameters.

Properties
Name Type Attributes Default Description
path string <optional>

Default: Wsh.DotEnv.envPathDefault. portable, userProfile, File Path

parsesDate boolean <optional>
false

Parses the path as the date literal. See https://docs.tuckn.net/WshUtil/Wsh.Util.html#.parseDateLiteral.

encoding string <optional>

Default: 'utf-8'. See Wsh.FileSystem.readFileSync

Returns:
  • Returns an Object with a parsed key containing the loaded content or an error key if it failed.
Type
object