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

envie

v4.1.1

Published

Tiny module to read and document environment configuration

Downloads

5,699

Readme

Build Status Coverage

node-envie

Tiny module to read and document environment configuration

Envie parses and validates configuration read from the environment via process.env. Uses Joi for validation.

Installation

npm install --save envie

Usage

const { Envie, Joi } = require('envie')

const envie = Envie({
  PORT: Joi
    .number()
    .min(0)
    .default(0)
    .description('Port on which the HTTP server will listen'),

  DATABASE_URL: Joi
    .string()
    .uri(({ scheme: ['postgres', 'mysql', 'sqlite'] }))
    .description('Connection string of the main database'),

  LOG_LEVEL: Joi
    .string()
    .only('fatal', 'error', 'warn', 'info', 'debug', 'trace')
    .default('info')
    .description('Level of verbosity for the logs')
})


// When you need to access your configuration
server.listen(envie.get('PORT'))
DatabaseService.use(envie.get('DATABASE_URL'))

Alternative usage

.values() validates your environment according to the schema

const { Envie, Joi } = require('envie')

const { PORT } = Envie({
  PORT: Joi
    .number()
    .min(0)
    .default(0)
    .description('Port on which the HTTP server will listen'),
}).values()

server.listen(PORT)

Keep in mind that this "freezes" the returned values where as envie.get(key) gets the current value every time. This may cause some issues when mutating process.env for testing purposes.

Notes

Undescribed keys can be requested as well but will not be validated.

You can also display a nicely formatted help output with colours

envie.displayHelp()
  PORT (number)
    Port on which the HTTP server will listen

  LOG_LEVEL (string, default: debug)
    Level of verbosity for the logs

  DATABASE_URL (string <uri:postgres|mysql|sqlite>)
    Connection string of the main database

The displayed message also accounts for current values. For example with PORT=8080 and LOG_LEVEL="hello world!"

  PORT (number)
    Port on which the HTTP server will listen
    overwritten: 8080

  LOG_LEVEL (string, default: debug)
    Level of verbosity for the logs
    overwritten: invalid! "LOG_LEVEL" must be one of [fatal, error, warn, info, debug, trace]

  DATABASE_URL (string <uri:postgres|mysql|sqlite>)
    Connection string of the main database

If you'd rather have the help message as a simple string, you can use:

const help = envier.helpString()

Reference

[new] Envie(description[, values=process.env], options={ noDefaults: false })

Creates a new envie instance which parses the keys of the object values using the description. description must be an object whose keys contain a Joi validator. By default, process.env is parsed. The new keyword is optional.

You can specifiy noDefaults to true to get undefined instead of default value for non set key. This is specially useful if you want to use default values on local environment but want to ensure all required keys have a defined values when application is deployed.

envie.get(key)

Reads the parsed value for key if present and valid. Throws if the value is not valid.

envie.has(key)

Returns true if the key is properly configured.

envie.validate()

Throws if any validator failed.

envie.values()

Validates env and returns values as an object.

envie.displayHelp([stream=process.stderr])

Outputs to the given stream a human readable description of the expected configuration

Test

You can run the tests with npm test. You will need to know mocha

Contributing

Anyone is welcome to submit issues and pull requests

License

MIT

Copyright (c) 2019 Florent Jaby

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.