Security News
NVD Backlog Tops 20,000 CVEs Awaiting Analysis as NIST Prepares System Updates
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
processenv
Advanced tools
processenv parses environment variables.
Category | Status |
---|---|
Version | |
Dependencies | |
Dev dependencies | |
Build | |
License |
$ npm install processenv
First you need to integrate processenv into your application:
const { processenv } = require('processenv');
If you use TypeScript, use the following code instead:
import { processenv } from 'processenv';
Then, to parse an environment variable, call the processenv
function and provide the name of the environment variable you would like to parse:
const port = processenv('PORT');
Please note that the value is automatically converted to the appropriate data type, e.g. a number
. This also works for stringified JSON objects, in case you want to store complex configuration data inside an environment variable.
If you want to provide a default value, you may add it as a second parameter. This also works for booleans and all other types. If neither the environment variable nor the desired default value are set, processenv
returns undefined
:
const port = processenv('PORT', 3000);
const user = processenv('USER', 'Jane Doe');
const isRoot = processenv('ROOT', true);
Alternatively, you may also provide a function which returns the default values. This is useful, e.g. if you want to lazily evaluate a value:
const port = processenv('PORT', () => 3000);
If you want to use an asynchronous function, please note that you must await
the call to processenv
:
const port = await processenv('PORT', async () => 3000);
??
operatorInstead of providing a second parameter, you may use the ??
operator to handle default values:
const isRoot = processenv('ROOT') ?? true;
Please note that this is only true if you are using the ??
operator. If you are using the old-style ||
operator instead, the previous line always returns true
, no matter what the actual value of the ROOT
environment variable is. To avoid this problem, either use the ??
operator or use the previously shown syntax using a second parameter to provide a default value.
If you want to get all environment variables at once, omit the name and simply call processenv
. The values will all be parsed, but you can not specify default values.
const environmentVariables = processenv();
To run quality assurance for this module use roboter:
$ npx roboter
FAQs
processenv parses environment variables.
The npm package processenv receives a total of 18,888 weekly downloads. As such, processenv popularity was classified as popular.
We found that processenv demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 5 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.
Security News
PyPI now supports digital attestations, enhancing security and trust by allowing package maintainers to verify the authenticity of Python packages.