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

dotenv-picker

v1.0.13

Published

Choose .env file when running your app

Downloads

38

Readme

Dotenv Picker

This is a manager for dotenv configuration files(.env). It provides more convenient way to select which configuration to use while a script run.

Features

Easy usage

Installation

npm install --save-dev dotenv-picker

Usage

Create script in your package.json, for ex:

{
  "scripts": {
    "start:dev": "node -r dotenv-picker/select your.script.js"
  }
}

Switch between .env files on a run

Dotenv Picker searches in the project's root for all files satisfying .env* pattern. Then it shows a simple UI allowing you to select which .env file to use during this run.

UI

Select .env file, hit ENTER and you are done!

Works with ts-node

Dotenv Picker may be used along with ts-node too:

{
  "scripts": {
    "start:dev": "ts-node -r dotenv-picker/select your.script.ts"
  }
}

Use shell to set environment variables

Sometimes you may need to call something like this:

{
  "your:command": "npx some.command"
}

In this case use:

{
  "your:command": "dotenv-picker npx some.command"
}

This will read variables from .env file and then will call npx some.command via execSync with environment variables passed into it.

Pass commonly used features via argv

Like dotenv package Dotenv Picker can read some configuration options from command line arguments:

{
  "scripts": {
    "start:dev": "node -r dotenv-picker/select your.script.js dotenv_config_path=.env.1 dotenv_picker_remember_last"
  }
}
  • dotenv_config_path - if there was no previous selection saved for your.script.js then .env.1 would be automatically selected on UI.
  • dotenv_picker_remember_last - instruct Dotenv Picker to remember selection for the next run

Configure via json configuration file

You may wish to configure Dotenv Picker behavior. Create dotenv-picker.json in your project's root for that:

{
  "searchPath": "./tests/data",
  "exclude": ["some-folder"],
  "rememberLastSelection": false,
  "exitWhenNoSelection": false,
  "defaultSelection": ".env.local",
  "scripts": {
    "./your.script.js": {
      "searchPath": "./tests/data/hierarchy",
      "exclude": ["node_modules"],
      "rememberLastSelection": true,
      "exitWhenNoSelection": false,
      "defaultSelection": ".env.local.special"
    }
  }

Configuration may be done per script. If you are starting your.script.js then you need to have the corespondent ./your.script.js field inside the scripts section.

Or you can set configuration globally for all scripts at once. The rule here is that script config has priority over the global config.

All of these settings are optional:

  • searchPath - where to search for the .env files.
  • exclude - exclude folders from search. More details here.
  • rememberLastSelection - remember .env file selection for the next script run.
  • exitWhenNoSelection - default is true. When true and you press ctrl+c process will immediately exit.
  • defaultSelection - when no selection was made previously this will be used as fallback. Useful in case you have only one .env and want it to be selected automatically not to block execution with selection ui. Set this value relative to the searchPath or to the project's root.

Remember previous selection per script

If you configured Dotenv Picker to remember selections then it will create and update .dotenv-picker-state.json in your project's root folder. You might wish to add it your control version ignore file. The content of this file may look like this:

{
  "scripts": {
    "./test.js": {
      "selection": "./tests/data/hierarchy/.env"
    },
    "./tests/check.js": {
      "selection": "./tests/data/.env.1"
    }
  }
}

As you can see Dotenv Picker stores selections per script.