npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fastify-check-runtime-env

v4.0.1

Published

Fastify Plugin to check runtime environment properties

Downloads

8

Readme

fastify-check-runtime-env

NPM Version NPM Downloads Code Style license - APACHE-2.0

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'), {
  // nodeStrictCheckAtStartup: true, // same as default
  nodeVersionCheckAtStartup: true,
  nodeVersionExpected: engines.node
  // nodeVersionExpected: '<=10.13.0 >=200.0.0', // sample failing test
  // onCheckMismatch: '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 ^4.0.1 , Node.js 14 LTS (14.15.0) or later. Note that plugin releases 3.x are for Fastify 3.x, 4.x are for Fastify 4.x, etc. Old plugin releases (0.x) are for Fastify 2.x but are now obsolete.

Sources

Source code is all inside main repo: fastify-check-runtime-env.

Documentation generated from source code (library API): here.

Note

The plugin decorate Fastify and expose some functions:

  • CheckRuntimeEnv, the checkers implementation, as a class (RuntimeEnvChecker); but note that to use it you need to wait for this plugin to be fully loaded and initialized

Plugin options are:

  • onCheckMismatch, define what to do if a checker fails (Node.js version does not match with the expected one, JavaScript not in strict mode, etc); 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
  • nodeStrictCheckAtStartup, flag to tell (when true) to check JavaScript strict mode; by default true (safer and already enforced as default mode in modern JavaScript code using classes, ES Modules, etc)
  • 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.