npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

processenv2

v2.0.2

Published

parse .env files to load variables to the process.env property automatically

Downloads

5

Readme

processenv2

use .env files in your projects

With processenv2 you have the opportunity to use environment variables directly in your project.
You can parse .env files and add them to the global variables process.env.
You can also specify default values with processenv2. These values are used if there is no environment variable.
This makes it easier to check for errors and use standard configurations.

You also have the option to define nested variables, arrays and objects in the environment file
You can use inline comments and masked hashtags (\#)

This module is compatible with processenv from TheNativeWeb. I would like to thank the team at TheNativeWeb very much.

Click here to go to the GitHub page of processenv by TheNativeWeb

TheNativeWeb GitHub

Click here to go to the npmjs page of processenv by TheNativeWeb

TheNativeWeb npmjs

Version 2.0.2

checkout the Changelog


Documentation

checkout the documentation

Installation

$ npm install processenv2

get environment variables

# this .env file is a example
MODE=live
IGNORED=${HOME_PATH}
HOME_PATH=/var/www
LOG_PATH=${HOME_PATH}/log
ACCESS_LOG='${LOG_PATH}/access.log'
ERROR_LOG=${LOG_PATH}/error.log
ERROR_MODE='{ "info": "${LOG_PATH}/info.log", "fatal": "${LOG_PATH}/fatal.log", "exception": "${LOG_PATH}/exception.log" }'
ERROR_MODE_ARRAY='[ "info\\#with masked hash", "fatal", "exception" ]'
INLINE_COMMENT='this is a inline comment #not parsed'
INLINE_COMMENT_WITH_ESCAPE='this is an inline comment \# with masked hash'

basic usage

const { processenv } = require('processenv2');
const home_path = processenv('HOME_PATH');

full usage

const { processenv } = require('processenv2');

const getAllEnv = processenv();
/* output: all environment  variables */

const getAllEnvCallback = processenv((env) => {
  return env;
});
/* output: all environment  variables */

const getEnvByKey = processenv('MODE');
/* output: live */

const getEnvByKeyWithDefaultValue = processenv('MODE_TYPE', 'live');
/* output: live - MODE_TYPE does not exist */

const getEnvByKeyWithDefaultByCallback = processenv('MODE_TYPE', (val) => {
  return val ?? 'live';
});
/* output: live - MODE_TYPE does not exist */

const getEnvByKeyWithOperator = processenv('MODE_TYPE') ?? 'live';
/* output: live - MODE_TYPE does not exist */

const getEnvByKeyWithValidateCallback = processenv('MODE', (val) => {
  return val === 'live';
});
/* output: true - MODE is available and is live */

const getEnvByKeyWithAsyncCallback = await processenv('MODE', async (val) => {
  return val === 'live';
});
/* output: true - MODE is available and is live */

const getEnvByKeyWithInlineComment = await processenv('INLINE_COMMENT');
/* output: this is a inline comment */

const getEnvByKeyWithInlineCommentWithEscapedHash = await processenv('INLINE_COMMENT_WITH_ESCAPE_HASH');
/* output: this is a inline comment # with escaped hash */

END

Did you find any suggestions or bugs? Make a pull request or ask your question :-)