Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/indexzero/node-pkginfo
An easy way to expose properties on a module from a package.json
https://github.com/indexzero/node-pkginfo
Last synced: 7 days ago
JSON representation
An easy way to expose properties on a module from a package.json
- Host: GitHub
- URL: https://github.com/indexzero/node-pkginfo
- Owner: indexzero
- License: mit
- Created: 2011-06-04T02:17:22.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2018-02-15T03:08:23.000Z (over 6 years ago)
- Last Synced: 2024-04-14T13:19:39.253Z (7 months ago)
- Language: JavaScript
- Homepage: http://github.com/indexzero/node-pkginfo
- Size: 30.3 KB
- Stars: 161
- Watchers: 5
- Forks: 26
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome - pkginfo - An easy way to expose properties on a module from a package.json. (Npm)
- awesome-nodejs - node-pkginfo - An easy way to expose properties on a module from a package.json. ![](https://img.shields.io/github/stars/indexzero/node-pkginfo.svg?style=social&label=Star) (Repository / NPM)
README
# node-pkginfo
An easy way to expose properties on a module from a package.json
### Installing pkginfo
```
npm install pkginfo
```## Motivation
How often when writing node.js modules have you written the following line(s) of code?* Hard code your version string into your code
``` js
exports.version = '0.1.0';
```* Programmatically expose the version from the package.json
``` js
exports.version = require('/path/to/package.json').version;
```In other words, how often have you wanted to expose basic information from your package.json onto your module programmatically? **WELL NOW YOU CAN!**
## Usage
Using `pkginfo` is idiot-proof, just require and invoke it.
``` js
var pkginfo = require('pkginfo')(module);console.dir(module.exports);
```By invoking the `pkginfo` module all of the properties in your `package.json` file will be automatically exposed on the callee module (i.e. the parent module of `pkginfo`).
Here's a sample of the output:
```
{ name: 'simple-app',
description: 'A test fixture for pkginfo',
version: '0.1.0',
author: 'Charlie Robbins ',
keywords: [ 'test', 'fixture' ],
main: './index.js',
scripts: { test: 'vows test/*-test.js --spec' },
engines: { node: '>= 0.4.0' } }
```### Expose specific properties
If you don't want to expose **all** properties on from your `package.json` on your module then simple pass those properties to the `pkginfo` function:``` js
var pkginfo = require('pkginfo')(module, 'version', 'author');console.dir(module.exports);
``````
{ version: '0.1.0',
author: 'Charlie Robbins ' }
```If you're looking for further usage see the [examples][0] included in this repository.
## Run Tests
Tests are written in [vows][1] and give complete coverage of all APIs.```
npm install
npm test
```[0]: https://github.com/indexzero/node-pkginfo/tree/master/examples
[1]: http://vowsjs.org#### Author: [Charlie Robbins](http://github.com/indexzero)
#### License: MIT