Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
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 21,625 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
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.