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

envlocker

v0.2.0

Published

Manage environment variables with 1Password. It is a wrapper around [the wrapper](https://github.com/1Password/op-js) for the [1password-cli](https://developer.1password.com/docs/cli/get-started/) that allows you to store environment variables in 1Passwor

Downloads

960

Readme

envlocker

Manage environment variables with 1Password. It is a wrapper around the wrapper for the 1password-cli that allows you to store environment variables in 1Password and load them in a way that is comparable to (and uses) dotenv.

Installation

Add the package using your favorite package manager:

$ pnpm add envlocker

Usage

You will need to create a .envlockerrc file at the root of your project:

{
  "development": {
    "item": "Cool app.jpeg", // required
    "vault": "envs", // optional
    "account": "my.1password.com" // optional
  },
  "production": {
    "item": "jtm2ddhxqwx8orfgfjxknzp5re" // can also be the UUID of the item
  }
}

The development and production keys are the names of the environments you want to use. You can add as many different environments with different names as you want. The default environment is development, but this can be configured with the ENVLOCKER_ENV_NAME environment variable.

The vault key is optional but is recommended to reduce the number of API calls to 1Password. The account key is also optional and defaults to whichever account op is currently logged into.

The account value can be any of the described by the 1password CLI documentation. The item and vault values and the accepted formats are described here in the 1password CLI docs.

Once you have created the .envlockerrc file, you can load the environment variables in a few different ways using envlocker.

Command line:

$ node -r envlocker/config ./index.js

or if using it with a different executable that doesn't pass flags to Node.js (e.g. Next.js):

$ NODE_OPTIONS='-r envlocker/config' pnpm next

Programmatically with import:

import 'envlocker/config';

or

import { config } from 'envlocker';
config();

Programmatically with require:

require('envlocker').config();

1password configuration

To configure the environment variables within 1password, you will need to create a new item and add the desired variables as individual fields within the new item. Fields with empty keys or values will be ignored. Fields are also ignored if they do not match the pattern ^[A-Z0-9_]+$.

API

config

Injects the environment variables into process.env. The environment name can also be passed as an argument to this function.

Uses dotenv to inject the environment variables.

import { config } from 'envlocker';

config({ envName: 'staging' });

createItemFromEnvFile

Creates a new item in 1password from a .env file. The .env file must be formatted as KEY=VALUE pairs, one per line. The title and vault options are required. The account option is optional and defaults to whichever account op is currently logged into. The category option is also optional and defaults to Server.

Uses dotenv to parse the .env file.

type CreateItemFromEnvFileOptions = {
  filePath: string;
  title: string;
  vault: string;
  account?: string;
  category?: op.InputCategory;
};

export const createItemFromEnvFile = async (
  options: CreateItemFromEnvFileOptions,
): Promise<op.Item>

Limitations

This package does not (yet) support 1password Connect Server access.