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

loadenv

v2.2.0

Published

Loads environment variables from project's `./configs/` directory based on NODE_ENV.

Downloads

113

Readme

loadenv

Build Status Dependency Status devDependency Status

NPM

Utility for loading environment variables from a project's configs/ directory.

How it works

The module first finds your application's root directory and then attempts to load environment variables found in the configs/.env file. Then, if a specific NODE_ENV exists in the environment at run time it additionally loads variables from the configs/.env.${NODE_ENV} file. Note: This module will not work if installed globally [npm install loadenv -g].

An Example

Suppose you have your project setup with the following configs:

configs/.env
  A=1
  B=2
configs/.env.test
  B=3
  C=4

If you launched your application without a NODE_ENV variable set, and called into the module like so:

require('loadenv')();

then the resulting process.env would now contain the following:

process.env.A === 1
process.env.B === 2

If instead, you launched your application with NODE_ENV=test then the process.env would include the following:

process.env.A === 1
process.env.B === 3
process.env.C === 4

Logging the Resulting Environment

The module uses debug to log the resulting environment after it has been loaded from the configs/ files. By default it uses debug('loadenv') but you can override this by calling into the module with a custom name, like so:

// Pass an options object:
require('loadenv')({
  debugName: 'myapp:env'
});

// Or just use a string if you only need the debug name
require('loadenv')('myapp:env') ;

If you were to do so then the module would use debug('myapp:env') to log the resulting output.

Only Loads Environment Once

No matter how many times you include the module, the environment is only loaded once. So feel free to sprinkle loads wherever they might be needed to make your code as modular as possible.

Developing

If you want to contribute, make sure that all tests pass with 100% coverage before submitting a pull request. Here's how to run the tests:

npm test

LICENSE

MIT