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

@sodefa/gitenvs

v1.4.1

Published

Save your environment variables in git - encrypted!

Downloads

1,780

Readme

Git Envs

Save encrypted environment variables directly in git.

Setup

  • Create a ts file in your root folder (we suggest createEnvFiles.ts)
  • Copy the following template into the file:
import { GenerateEnvFilesFunction, Keys, main } from '@sodefa/gitenvs'

type Stage = 'production' | 'staging' | 'development'

const generateEnvFiles: GenerateEnvFilesFunction<Stage> = ({
  resolveSecret,
}) => {
  return [
    {
      envFilePath: 'path/to/your/app/.env.local',
      envVars: [
        {
          key: 'ENV_NAME',
          values: {
            default: 'EMPTY',
            production: resolveSecret(''),
            staging: resolveSecret(''),
            development: resolveSecret(''),
          },
        },
      ],
    },
  ]
}

const keys: Keys<Stage> = {
  production: {
    publicKey: '',
    encryptedPrivateKey: '',
  },
  staging: {
    publicKey: '',
    encryptedPrivateKey: '',
  },
  development: {
    publicKey: '',
    encryptedPrivateKey: '',
  },
}

main({
  generateEnvFiles,
  keys,
})
  • Setup the stages as you need them
    • development is the default stage that is used if you do not specify any stage
  • Create new public / private keys for every stage you defined by running npx ts-node createEnvFiles.ts createKeys (or how you called your file)
    • Copy the object with publicKey & encryptedPrivateKey and paste them into the keys object in your createEnvFiles.ts file
    • !WARNING! Do not copy & paste the passphrase into createEnvFiles.ts. It is a secret! Save it into your password manager.
  • Add the following command to your package.json:
    • "env:create": "npx ts-node createEnvFiles.ts createEnvFiles"
    • "env:ui": "npx nodemon createEnvFiles.ts ui"
    • "prepare": "yarn env:create" (This is so that the .env files will be created after node_modules were installed)
  • Add *.passphrase to your .gitignore

Adding new environment variables

  • Start the UI by running yarn env:ui and go to http://localhost:1337
  • Define environment variables in your createEnvFiles.ts file
    • The default value will be used if no value for the current stage is provided
    • If you want to use an encrypted enviroment variable go to the UI and enter the plaintext under Encryption
    • Copy the encrypted secret and paste it into the resolveSecret function. Example: resolveSecret('jk3Z35gkHKQtWlLWl4HXdhEJQAJdyIHTzQ4nH/uq84+SdD2ty2Q6qEECfjbAr79U65slD+8BxmFbSMwkAFdXtpkJpw+vHzwi+uVbMIDuq/yHW39XQ9Tv+5qGO3xIZnnE1HrkIOYNFc5O+YLb5dsBTasBwbMrVEBSUL1jA7NdL1IHo9lidrMPFfPxTdyB6COfuhu+UBq1MSXvjVabXXYuU2LXCBVeGhfRRVqs9lxPzb0ilplldsxns3nWRc3g2C5mOc3P2Ki9PjPEmaSvAi/CDgtrXuhMQ4yjeTTLmsZ9iDzyC9RR6apoJBj0NMkFxrnoJg/gG9Jyrgofbi2vfgmchFTPNB41KggNFEMGf428oihXW/k0o9tZWkyiCkXyysjHNJ/hz5g10tEBII1DTifWSe4H2LAfvAliOz8EzTMopXnra5LjlP1exDiTBTwg1GQj6VJ0tcYGnDLkGbkHVXZSZxQwgHWyUKcipb3J2O+21qMWcsRPGo4mzH0X6ORKnD+v4oGI34YDvcedMuQEfs2pmmX+EYwQx3TRgNk6Uy3ZAU84nM2z3IFeLBjhra5/mIH68y/MFMN/Kle6lEa28RR3bz2ToMDrDfvEyIQV+T2X0h8YiUDhol6UWA6OPGY8p2xS8Inz/byQCjbPO0z9hk1Vq9nzMkaupAy/KzZcorwtSPc=')

Decrypting environment variables locally

  • This is for debugging purposes only
  • Copy the passphrases you got from the createKeys command and paste them into the textarea under Decryption
  • All secrets will be revealed

Setting up local dev environment

  • You want to give all your developers the development passphrase so that they can work
  • You can send them a file called development.passphrase which just contains the passphrase
  • They should place it under the root folder and the local .env files will be created if they run env:create / yarn install

Setting up servers

  • On servers you want to provide the passphrase through environment variables. You have to provide two env vars:
  • GITENV_STAGE defines which stage should be used
  • GITENV_PRIVATE_KEY_PASSPHRASE_${stageName} contains the passpharse. Replace ${stageName} with the stage name you used in GITENV_STAGE