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

pigura

v1.0.1

Published

[![npm version](https://badge.fury.io/js/pigura.svg)](https://badge.fury.io/js/pigura)

Downloads

2

Readme

Pigura

npm version

Simple configuration file loader.

What is It?

  1. Let's say you have a file named config.json containing your app settings.

  2. You have a file named config.prod.json containing your app settings for PRODUCTION.

  3. Running your app on development mode, will only load config.json.

  4. Running your app in production, will load both config.json, MERGED with config.prod.json

  5. You dont need to copy all the settings from config.json to config.prod.json. Just the settings to override. Removing the need to maintain both files in sync.

Install

Choose 1 of 3 options:

Install from NPM:

npm install pigura

Install latest from GitHub:

npm install github:kosinix/pigura

Tied to a specific version/release from GitHub:

npm install github:kosinix/pigura#1.0.0

Quickstart

You only need to provide 3 parameters:

  • configName - The path to your config file relative to your app's root dir

  • appDir - App's root dir

  • env - The env variable. The default value is "dev". Any other value will load the config file + config.env file. See Convention.

  • logging (optional) - true to use console.log

      const pigura = require('pigura');
    
      let configLoader = new pigura.ConfigLoader({ 
          configName: './config.json',
          appDir: path.resolve(__dirname),
          env: 'dev'
      })
    
      let config = configLoader.getConfig();
      console.log(config)

Examples

The recommended way to switch between environments is to use NODE_ENV. There are other ways as well but pigura does not care how you get the env variable.

Production Environment using NPM Script

In your package.json scripts section

{
    ...
    "scripts": {
        "prod": "set NODE_ENV=prod&& node index.js",
    }
    ...
}

In the command line you type:

npm run prod

Then in your main file:

let configLoader = new pigura.ConfigLoader({ 
    configName: 'config.json',
    appDir: path.resolve(__dirname),
    env: process.env.NODE_ENV // Pass to pigura
})
let config = configLoader.getConfig();
console.log(config)

This will:

  • Read the contents of config.json
  • Read config.prod.json and merged it with config.json. The same settings in config.prod.json will override the settings in config.json

Get Base Config Only

You can get the base config only, disregarding the env variable, and child configs:

let config = configLoader.getConfig(true);

Convention

Naming

Base config:

`${configName}.json` - config.json

Child configs:

`${configName}.${env}.json` - config.sandbox.json

Why "." as separator for env?

So you can name your configs with dash separators:

config-foo-bar.json
config-foo-bar.sandbox.json
config-foo-bar.prod.json

Or:

configFooBar.json
configFooBar.sandbox.json
configFooBar.prod.json

Test

Install mocha globally

npm install mocha -g

Run test

npm test