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.
@ifaxity/env
Advanced tools
Node 6 or above is required as ES6 is needed.
Code heavily based on dotenv package on npm
npm install @ifaxity/env --save
or if you use yarn
yarn add @ifaxity/env
To use the module just require it like this
const env = require('@ifaxity/env');
Example .env file:
# Node environment
NODE_ENV=production
# Example database connect options
DB_HOST='localhost'
DB_PORT=27017
# Decimals can also be used
PI=3.14
# Booleans too
DEBUG=true
# Multiline strings (must be double quoted strings)
MULTILINE="Hello\nWorld!"
The module is a proxy object so you can use this to get an environment variable and also convert it to the correct type. As node.js doesn't support process.env
to have any other values other than strings for now.
Types parsed are limited to boolean, number, string
for now.
If the variable doesnt exist then null
is returned.
Like this:
Consider the variables in the example file above
const env = require('@ifaxity/env');
env.NODE_ENV // same as process.env.NODE_ENV.
env.PORT // returns 3000 (as a number)
env.BOOL // returns true (as a boolean)
// Can also use the object deconstruction syntax
const { NODE_ENV, PORT, TRUE } = require('@ifaxity/env');
However parse
& config
is reserved as functions in this module.
Configures and loads the environment variables from a file.
Returns the parsed variables in a form of an object. However unlike the module these variables are not proxied.
opts {Object} - Optional options. If any of the optional options is not of a valid type or if its value is not valid then a TokenError
will be thrown.
encoding {String}
- Encoding to use when reading the env files. Encoding types are defined in the nodejs documentation
path {String|Array}
- Full path to the directory to look for files. Files are loaded in order of .env, .env.${NODE_ENV} and .env.local. If a overwriting the earlier files if there are duplicate keys. Default value is the current working directory.
env {Object}
- Object to set the config options to. Default value is process.env.
defaults {Object}
- Object to set default values if a key doesn't exist in the .env file. Default value is null.
const env = require('@ifaxity/env');
// Basic usage
env.config();
// Custom path & variable
const envVars = env.config({
path: __dirname,
env: {},
});
Parses a key=value pair string to an object of variables
Returns an object of the key=value
pairs of the data
key=value
pair format.const env = require('@ifaxity/env');
const envVars = env.parse(fs.readFileSync(process.cwd() + '/.env', 'utf8'));
FAQs
Node 6 or above is required as ES6 is needed.
The npm package @ifaxity/env receives a total of 9 weekly downloads. As such, @ifaxity/env popularity was classified as not popular.
We found that @ifaxity/env demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.