Show the current version, author, and dependencies for a node script

It’s often useful to have an application know about itself: you can use the current version to identify data for required for migrations, expose a list of libraries you use for debugging purposes, or create screens that show end users license and author information for your application.

In a node script, you can pull this information by importing your own package.json:

let me = require('./package.json');
let version = me.version,
    author = me.author,
    dependencies = me.dependencies;

This is an example output:

Gary Sieling
1.0.0
{ async: '^2.0.0-rc.1',
  bluebird: '^3.3.4',
  dropzone: '^4.3.0',
  'eventsource-polyfill': '^0.9.6',
  express: '^4.13.4',
  'express-http-proxy': '^0.6.0',
  jquery: '^2.2.1',
  jsx: '^0.9.89',
  lodash: '^4.5.1',
  morgan: '^1.7.0',
  react: '^0.14.7',
  'react-bootstrap': '^0.28.3',
  'react-dom': '^0.14.7',
  'react-router': '^2.0.0',
  request: '^2.69.0',
  'request-promise': '^2.0.1',
  webpack: '^1.8.11',
  'webpack-dev-middleware': '*',
  'webpack-hot-middleware': '^2.7.1' }

Leave a Reply

Your email address will not be published. Required fields are marked *