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

sync-dotenv

v2.7.0

Published

Keep your .env in sync with .env.example

Downloads

6,082

Readme

Motivation

Projects often rely on environmental variables stored in a .env file to run... and because these variables sometimes contain sensitive data, we never add them to source control. Instead, these variables are added e.g. to a .env.example file so it's easy to get the project running for other developers. However, it's very easy to forget to update this file when a variable is added/updated in .env (during development). This can make it difficult for devs to get the project running (locally) because they rely on .env.example file to setup their environment (with their own configs).

Enter sync-dotenv 🔥

Description

sync-dotenv automates the process of keeping your .env in sync with .env.example.

Installation

$ npm install -g sync-dotenv

Install as a dev dependency (recommended)

$ npm install -D sync-dotenv

Usage

By default, sync-dotenv looks for a .env in your working directory and attempt to sync with .env.example when no argument is provided. Failure to find these files will cause the sync to fail.

$ sync-dotenv

Alternatively, you can use the --env and --sample flag to specify the source and destination file.

$ sync-dotenv --env foo/.env --sample bar/.env.example

Also, in the situation where you want to keep multiple files in sync with one source env file you can make use of the --samples flag specifying a globbing pattern to match:

$ sync-dotenv --env foo/.env --samples "env-samples/*"

# note: glob pattern should be provided as a string as shown above

For CLI options, use the --help flag

$ sync-dotenv --help

Examples

Sync (with .env.example) before every commit using husky

// package.json
{
  "scripts": {
    "env": "sync-dotenv"
  },
  "husky": {
    "hooks": {
      "pre-commit": "npm run env",
    }
  }
}

Or with file other than .env.example

{
  "scripts": {
-    "env": "sync-dotenv"
+    "env": "sync-dotenv --sample .env.development"
  }
}

Preserving variables in sample env

Sometimes you need to preserve certain variables in your example env file, you can optionally allow this by adding a sync-dotenv config in package.json like so

// package.json
"scripts": {
  ...
},
"sync-dotenv": {
  "preserve": ["CHANNEL"]
}

Avoid comments or empty lines in sample env

You might not want to copy empty lines or comments to your sample env, in this case you can still use sync-dotenv config in package.json with the following:

// package.json
"scripts": {
  ...
},
"sync-dotenv": {
  "emptyLines": true,
  "comments": false
}

Note that you can still combine those options with preserve.

Related

  • parse-dotenv - zero dependency .env to javascript object parser

Contributors

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!

License

This project is licensed under MIT