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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@devnetic/load-env

v1.1.0

Published

Works with environment variables from .dot files

Downloads

6

Readme

@devnetic/load-env

npm (scoped) npm bundle size (scoped) npm GitHub issues GitHub

load-env is a zero-dependencies module to work with environment variables from .env files, or any .dot files with the same structure.. This last feature is one of the main differences with another similar packages, because with load-env you can read not just .env files, you can read any .dot file o similar files with an equivalent structure.

Another main feature is the possibility to save config values to a .dot file.

Usage

loadEnv.load(filename: string = '.env', options: LoadOptions = {}): void | Config

LoadOptions {
  returnConfig?: boolean
  separator?: string
}

To load a .env file just run the load() function in the loadEnv module.

import * as loadEnv from '@devnetic/load-env' // or
// const loadEnv = require('@devnetic/load-env')

loadEnv.load()

But if you want return the config values in an object instead of set process.env, you can use the load() function returnConfig parameter.

import * as loadEnv from '@devnetic/load-env' // or
// const loadEnv = require('@devnetic/load-env')

const config = loadEnv.load('your_path_to/.env', { returnConfig: true })

To load .dot files different to .env just run the load() function in the loadEnv module with the necessary file path.

import * as loadEnv from '@devnetic/load-env' // or
// const loadEnv = require('@devnetic/load-env')

loadEnv.load('your_path_to/.errors-description', { separator: `\r\n`})

The default line separator for .dot files is '\n', but you can use a different separator using the load() function options parameter.


loadEnv.set(key: string, value: string): void

To set a value in process.env just run the set() function in the loadEnv module with the necessary key and value.

import * as loadEnv from '@devnetic/load-env' // or
// const loadEnv = require('@devnetic/load-env')

loadEnv.set('KLE0003', 'Error message 03')

Now the new value is available in process.env.KLE0003.


loadEnv.parse(config: string, options: ParseOptions = {}): Config

To parse values just run the parse() function in the loadEnv module with the necessary config values in the follow format key1=value1\nkey2=value2. By default this function returns an object with the parsed keys and values, but could set the values in process.env too, just setting the parameter createEnv to true in the options parameter.

ParseOptions {
  createEnv?: boolean
  separator?: string
}
import * as loadEnv from '@devnetic/load-env' // or
// const loadEnv = require('@devnetic/load-env')

const config = loadEnv.parse('KLE0003=Error message 03')
console.log(JSON.stringify(config)) // { "KLE0003": "Error message 03" }

loadEnv.parse('KLE0002=Error message 02\nKLE0003=Error message 03', { createEnv: true })
// Now the new value are available in process.env.KLE0002 and process.env.KLE0003

loadEnv.save(filename: string, config: Object, separator: string = '\n' ): boolean

To save a config to a .dot file, you can use the loadEnv's .save() function.

import * as loadEnv from '@devnetic/load-env' // or
// const loadEnv = require('@devnetic/load-env')

const config = { DB_HOST: 'localhost', DB_USER: 'root', DB_PASS: 's1mpl3' }

loadEnv.save('your_path_to/.env-dev', config)