3 An easy way to expose properties on a module from a package.json
7 ### Installing npm (node package manager)
9 curl http://npmjs.org/install.sh | sh
12 ### Installing pkginfo
14 [sudo] npm install pkginfo
18 How often when writing node.js modules have you written the following line(s) of code?
20 * Hard code your version string into your code
23 exports.version = '0.1.0';
26 * Programmatically expose the version from the package.json
29 exports.version = require('/path/to/package.json').version;
32 In other words, how often have you wanted to expose basic information from your package.json onto your module programmatically? **WELL NOW YOU CAN!**
36 Using `pkginfo` is idiot-proof, just require and invoke it.
39 var pkginfo = require('pkginfo')(module);
41 console.dir(module.exports);
44 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`).
46 Here's a sample of the output:
50 description: 'A test fixture for pkginfo',
52 author: 'Charlie Robbins <charlie.robbins@gmail.com>',
53 keywords: [ 'test', 'fixture' ],
55 scripts: { test: 'vows test/*-test.js --spec' },
56 engines: { node: '>= 0.4.0' } }
59 ### Expose specific properties
60 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:
63 var pkginfo = require('pkginfo')(module, 'version', 'author');
65 console.dir(module.exports);
70 author: 'Charlie Robbins <charlie.robbins@gmail.com>' }
73 If you're looking for further usage see the [examples][0] included in this repository.
76 Tests are written in [vows][1] and give complete coverage of all APIs.
79 vows test/*-test.js --spec
82 [0]: https://github.com/indexzero/node-pkginfo/tree/master/examples
83 [1]: http://vowsjs.org
85 #### Author: [Charlie Robbins](http://nodejitsu.com)