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

@naturacosmeticos/check-environment-variables

v0.0.1

Published

Check needed environment variables

Downloads

17

Readme

Known Vulnerabilities Build Status Codacy Badge

check-environment-variables

Check environment variables helps verify variables set by setup files (ex: spec.yaml) and also in the environment itself.

How to use

If you want to check your environment variables you can run: check-variables, when you execute this binary file it will look for a file, on the same level with the name checkVariablesSpec.yaml, and it is going to compare the variables on the process.env and compare against the specification on the file.

See this example file:

checkVariables:
  START_SERVER: # required boolean variable (true or false)
    type: boolean
    required: true
  REQUEST_TIMEOUT: number # not require number
  API_HOST: url # not required url
  FROM_EMAIL: email # not required url
  NAMESPACE: string # not required string
  ENDPOINT: true # required variable to have on process.env
  AWS_REGION: # the variable value should be one of the possibleValues
    type: enum
    possibleValues:
      - us-east-2
      - us-east-1
      - us-west-1
      - us-west-2
  MY_OTHER_VARIABLE: # an string, starting with maria, with length from 7 to 20
    type: string
    required: true
    minLength: 7
    maxLength: 20
    regex: ^maria

If you run check-variables against this file it is going to check the varaibles START_SERVER, REQUEST_TIMEOUT, API_HOST, FROM_EMAIL, NAMESPACE, ENDPOINT, AWS_REGION, MY_OTHER_VARIABLE on your process.env

Options of check-variables:

# default value for yamlFile is "checkVariablesSpec.yaml"
Usage: check-variables [options] [yamlFile]

Options:
  -V, --version                output the version number
  -b, --bail                   Indicates whether or not the proccess exits with status non ok when oneor more variables are wrong
  -f, --formatter [formatter]  The formatter of output: json, inline, pretty (default: "pretty")
  -h, --help                   output usage information

In order to check variables in a spec file, you need to run: validate-spec-yaml [MY_SPEC_FILE_PATH]

The comparison will occur according to the templates files in /templates.

Using programatically

const checkVariables = require('check-variables');

const myVariables = {
  myServerShouldStart: process.env.START_SERVER,
  region: process.env.REGION
}

// follow the same specification of "checkVariablesSpec.yaml" file
const mySpecification = {
  myServerShouldStart: 'boolean',
  region: {
    type: 'enum',
    possibleValues: ['north', 'south']
  }
}
const result = checkVariables(myVariables, mySpecification) // as the first parameter you can also use process.env
result.assertVariablesAreOK() // throws an AssertionError if something is not right
result.success // false when the specification is not valid, true when validation happened
result.messages // when at least one of the specification are invalid you can see what is invalid
result.hasErrors  // false when all variables respects the rules in specification
result.variables // an array, items has the fields: 'variable' -> name of the variable, 'value' -> the value of variable, 'error' -> null if the value of the variable is ok against the rule, string containing the error if not ok

Supported setup files

The current version only supports spec.yaml, an internal Natura environment setup file.

Setup

Run npm i.

Testing

Just run npm test.

Lint

To verify if any lint rule was broken run: npm run lint.

How to contribute

You can contribute submitting pull requests.