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

smenv

v0.1.0

Published

Sync AWS Secret Manager secrets with .env file

Downloads

1

Readme

smenv

smenv is a Node.js library and command-line tool for fetching secrets from AWS Secrets Manager and updating local environment files. It allows you to keep your sensitive information securely in AWS Secrets Manager and easily sync it with your local environment files.

Installation

You can install smenv as a dependency in your Node.js project using npm or yarn:

npm install smenv

or

yarn add smenv

Usage

Library

You can use smenv as a library in your Node.js code as shown in the following example:

const smenv = require('smenv')
const isEmpty = require('lodash.isempty')
  
;(async () => {
  const result = await smenv({
    secretName: 'mySecret', // The name of the secret to fetch from AWS Secrets Manager
    packageName: 'myApp', // The name of the package (optional, default is value from package.json in current directory)
    env: 'production', // The environment name (optional, default is NODE_ENV environment variable or 'development')
    fileName: '.env.prod', // The name of the file to write secrets to (optional, default is '.env')
    backupFileRetentionAmount: 5 // The number of backup files to retain (optional, default is 3)
  })

  if (!result.isDiff) {
    console.log(
      `Local file "${result.fileName}" is synced with "${result.secretName}"`
    )
  } else {
    console.log(
      `Diff found from local file "${result.fileName}" to "${result.secretName}":`
    )
    const { added, deleted, updated } = result.filesDiff

    if (!isEmpty(added)) {
      console.log(
        `Added ${Object.keys(added).length} secrets: ${JSON.stringify(added)}`
      )
    }
    if (!isEmpty(deleted)) {
      console.log(
        `Removed ${Object.keys(deleted).length} secrets: ${JSON.stringify(
          deleted
        )}`
      )
    }
    if (!isEmpty(updated)) {
      console.log(
        `Updated ${Object.keys(updated).length} secrets: ${JSON.stringify(
          updated
        )}`
      )
    }
    if (result.backupFileName) {
      console.log(`Backup file created: ${result.backupFileName}`)
    }
    if (result.deletedFiles) {
      console.log(`Old backup files deleted: ${result.deletedFiles}`)
    }
  }
})()

Command-line tool

You can also use smenv as a command-line tool by running the smenv command with the following options:

Usage: cli.js [options]

Options:
      --help             Show help                                     [boolean]
      --version          Show version number                           [boolean]
  -s, --secretName       The name of the secret to fetch from AWS Secrets
                         Manager                                        [string]
  -p, --packageName      The name of the package
                [string] [default: value from package.json in current directory]
  -e, --env              The environment name
              [string] [default: NODE_ENV environment variable or 'development']
  -f, --fileName         The name of the file to write secrets to
                                                        [string] [default: .env]
  -r, --backupRetention  The number of backup files to retain
                                                           [number] [default: 3]

Examples:
  cli.js --secretName mySecret              Fetches the specified secret from
                                            AWS Secrets Manager
  cli.js --packageName myApp --env          Specifies custom package name and
  production                                environment
  cli.js -s mySecret -p myApp -e            Specifies all options at once
  production -f .env.prod -r 5

License

This project is licensed under the Apache-2.0