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

secrets-encrypt

v0.0.9

Published

util for encrypting application secrets before storing in repository

Downloads

13

Readme

Secrets Encrypt

A helper utility for a really opinionated way of setting up your projects config.

We assume that you have the following setup

├── project/
│   ├── configkey.js    
│   ├── start.js
│   ├── environments/
│   │   ├── appA.js
│   │   ├── appB.js
│   │   ├── parts/
│   │   │   ├── secrets.js
│   │   │   ├── secrets.enc.js
│   │   │   ├── common.js

The start script start.js using a a build variable say BUILD should be set to appA or appB which are then loaded from the environments/appA.js or environments/appB.js using require. These files themselves should depend on common config in for example parts/common.js and in particular, in the case of credentials should load them from secrets.js.

During encryption/decryption a key is used which can be defined through either a file or another environmental variable.

Usage

Install

npm i secrets-encrypt -S

Add the following in your package.json:

"scripts": {
    "encrypt": "node secrets-encrypt",
    "decrypt": "node secrets-encrypt"
}

Add the following to .gitignore:

secrets.js
configkey.js

For local development you should create a configkey.js should be used, here's a template:

/**
 *  Config key for decrypting sensitive environment config
 *  Do not store in repo!
 */

module.exports = 'yourSecretKey';

configkey.js is suitable for local development, however for production environments where its difficult to have files that are not checked into the repository you can set the environment variable CONFIGKEY.

Running

Add a file in your

Encrypt / decrypt your secrets file.

npm run encrypt
npm run decrypt

expects:

  • "secrets.js" in environments/parts/secrets.js during encrypt
  • "secrets.enc.js" in enviroments/parts/secrets.enc.js during decrypt
  • one of the following methods of providing a key:
    • CONFIGKEY environment variable
    • configkey.js file in the root of the project

Motivation and benefits

This config setup maybe goes against everything you know about setting up configuration. You probably store all of your config in a separate place and/or you never check it into the repository. In addition the config is probably written in some format that is not native to Node.js.

While I agree with most of the tenants of the 12 factor app I find the complexity of replicating and editing config that goes with my applications when they are stored in files that don't lend themselves to all the benefits of modern node.js to be an incredible burden. These include:

  • having to use a preprocessor to convert into a native js object
  • having to use different config files for runtime environments (like a dotenv file for local dev and something else for production)
  • having to repeat myself constantly
  • does not lend itself to self-documentation, and the ability to include comments is seldom possible.

For this reason I tend to specify all my application config through plain js files but encrypt application secrets and allow choosing of one build or another through an environmental variable.