Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including pkginfo with all npm packages installed. Try it out:

var pkginfo = require("pkginfo")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

pkginfo v0.4.1

An easy way to expose properties on a module from a package.json


An easy way to expose properties on a module from a package.json

Installing pkginfo

  npm install pkginfo


How often when writing node.js modules have you written the following line(s) of code?

  • Hard code your version string into your code
  exports.version = '0.1.0';
  • Programmatically expose the version from the package.json
  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!


Using pkginfo is idiot-proof, just require and invoke it.

  var pkginfo = require('pkginfo')(module);


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:

  var pkginfo = require('pkginfo')(module, 'version', 'author');

  { version: '0.1.0',
    author: 'Charlie Robbins <>' }

If you're looking for further usage see the examples included in this repository.

Run Tests

Tests are written in vows and give complete coverage of all APIs.

  npm install
  npm test

Author: Charlie Robbins

License: MIT


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free