Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

fastify-check-runtime-env

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-check-runtime-env

Fastify Plugin to check runtime environment properties

  • 0.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

fastify-check-runtime-env

NPM Version NPM Downloads Code Style Coverage Status dependencies Status devDependencies Status

Fastify Plugin to check runtime environment properties

The purpose of this plugin is to let Fastify web applications do some checks on some properties available at runtime (for example at application startup). By default any checker method that doesn't satisfy its condition will throw Error, but in some cases this is configurable via plugin options.

Note that all Chechers features exposed here are in the the library check-runtime-env. For Semantic Versioning checks, see semver.

Usage

A common use case is to throw an exception at application startup, if Node.js version is not compatible with the one set in package.json.

const fastify = require('fastify')()
const engines = require('../package.json').engines

// register plugin with some options
fastify.register(require('fastify-check-runtime-env'), {
  nodeVersionCheckAtStartup: true,
  nodeVersionExpected: engines.node
  // nodeVersionExpected: '>=16.0.0', // sample failing test
  // onNodeVersionMismatch: 'exception' // throw an exception // same as default
})

fastify.listen(3000)
// curl http://127.0.0.1:3000/ => returning the home page, if current Node.js versio in compatible with the expected one

In the example folder there are some simple server scripts that uses the plugin (inline but it's the same using it from npm registry).

Requirements

Fastify ^2.1.0 , Node.js 8 LTS (8.9.x) or later.

Note

The plugin decorate Fastify and expose some functions:

  • CheckRuntimeEnv, the checkers implementation, as a class (RuntimeEnvChecker)

Plugin options are:

  • onNodeVersionMismatch, define what to do if Node.js version does not match with the expected one; by default 'exception' to raise an Error, but could be 'warning' (to log a message in Fastify logs), or 'exit' (to stop current Node.js process) with exit code 1
  • nodeVersionCheckAtStartup flag to tell (when true) to check Node.js version at application startup; by default false
  • 'nodeVersion' the current Node.js version (by default 'process.version')
  • nodeVersionExpected, the semver string with the expected Node.js version (by default empty, so must be manually provided, for example reading 'package.json' attribute 'engines.node' if specified)

all plugin options are optional, and have a default value.

License

Licensed under Apache-2.0.


Keywords

FAQs

Package last updated on 06 Jun 2019

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