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

env-has

v0.0.3

Published

Checks that all parameters specified on the command line are defined and not empty in the environment.

Downloads

10

Readme

ENV-HAS

Checks that variable names specified as parameters on the command line are defined in the ENVIRONMENT.

If any of parameters is undefined, null or empty string, process exits with code 1 (Error), otherwise returns with code 0 (Success).

Usage

You can use env-has command in package.json scripts to check presence of certain environment variables. You can do a simple guard that allows you to run your script succesfully only if you specify all environment variables before run.

You can easily block unwanted npm publish with env-has during your npm package development.

Example

If you want to use env-has to block unwanted package publication, you only need to do those things:

  1. Put env-has into devDependencies in package.json:
  "devDependencies": {
    "env-has": "^0.0.1"
  }
  1. Add env-has check for ALLOW_NPM_PUBLISH environment variable into prepublishOnly script in package.json (or any other lifecycle script that is called before npm publish):
  "scripts": {
    "prepublishOnly": "env-has ALLOW_NPM_PUBLISH"
  }

Now if you suddenly use npm publish, it will fail in prepublishOnly with this error:

$ npm publish

> [email protected] prepublishOnly .
> env-has ALLOW_NPM_PUBLISH

Environment variable "ALLOW_NPM_PUBLISH" is not defined.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] prepublishOnly: `env-has ALLOW_NPM_PUBLISH`
npm ERR! Exit status 1

If you are ok with your package and want to publish it, call npm publish with arbitrary value in ALLOW_NPM_PUBLISH like this (here we use value yes):

$ ALLOW_NPM_PUBLISH=yes npm publish

This is really usefull if you can't/don't want to use private: true or publishConfig in your package.json.