DotEnv-like module for WSH (Windows Script Host) that reads/writes environment values in a .env file.
Requires
Members
(static, constant) envPathDefault :string
The path of .env directory in the current directory.
Type:
- string
(static, constant) envPathPortable :string
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
The path of .env directory in the user's directory (%USERPROFILE%). Ex. C:\Users<Name>.env
Type:
- string
Methods
(static) config(optionsopt) → {object}
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
|
Returns:
- Returns an Object with a
parsedkey containing the loaded content or anerrorkey if it failed.
- Type
- object