New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

express-package-json

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-package-json

express middleware to expose the contents of package.json to the view engine via res.locals

  • 1.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
29
decreased by-17.14%
Maintainers
1
Weekly downloads
 
Created
Source

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

Keywords

FAQs

Package last updated on 26 May 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc