package-json-config

0.2.0 • Public • Published

package-json-config

Making it easy for your npm package to save its config in the host application's package.json.

Installation

npm install package-json-config

Usage

Some App is an application that has taken a dependency on your npm package, Greeter.

// some-app/package.json
{
  "name": "some-app",
  "greeterConfig": {
    "recipient": "Mr. Anderson"
  }
}
// some-app/index.js
const greet = require('greeter')
greet()
// some-app/node_modules/greeter/index.js

const getConfig = require('package-json-config')
const config = getConfig('greeterConfig')

module.exports = function () {
  console.log(`Hello, ${config.recipient}.`) // Hello, Mr. Anderson.
}

Documentation

In this repo, you can find a working example and instructions for how to run it.

The Important Caveat

You must use package-json-config in the entry-point module of your npm package. It uses module.parent.parent to find the module using your package so you must use package-json-config in the entry point (index.js) of your package. If you find this makes using package-json-config too difficult in your package, submit a new issue describing your scenario and I'll see what I can do. Pull requests are encouraged as well 😉

Package Sidebar

Install

npm i package-json-config

Weekly Downloads

0

Version

0.2.0

License

MIT

Unpacked Size

2.84 kB

Total Files

3

Last publish

Collaborators

  • locksmithdon