express-package-json

1.0.3 • Public • Published

express-package-json

Simple express function to expose the contents of a package.json file to the view engine. This is useful for displaying the software version on a web page without having to update the page every time the version changes in package.json.

Installation

npm install --save express-package-json

API

expressPackageJson(pathToPackageJson, propertyName)

Parameters:

  • pathToPackageJson - path to the package.json file. String. Defaults to ./package.json.
  • propertyName - name of property to add to res.locals. String. Defaults to pkg.

Returns:

  • express middleware function:
    • middleware function accepts (req, res, next).
    • res.locals[variableName] is set to a JavaScript object containing the parsed package.json.
    • next() is called when complete.

Example

app.js:

"use strict";

var express = require('express');
var expressPackageJson = require('express-package-json');

var app = express();

app.set('view engine', 'hbs');    

app.use(expressPackageJson(path.join(__dirname, 'package.json')));

app.get('/', function (req, res) {
    res.render('index');
});

views/index.hbs:

{{pkg.name}} v{{pkg.version}}

Testing

npm test

License

See LICENSE.md

Package Sidebar

Install

npm i express-package-json

Weekly Downloads

20

Version

1.0.3

License

ISC

Unpacked Size

4.93 kB

Total Files

9

Last publish

Collaborators

  • tcort