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

cnn-hapi

v2.5.2

Published

This is a generic Hapi server for starting projects.

Downloads

35

Readme

CNN Hapi

Basic Hapi server with some baked in features that can be pulled in as a dependency of another application to extend as needed.

build node npm npm-downloads dependency-status

Features include:

  • Swagger on /documentation
  • Basic healthcheck on /__health
  • Basic logging
  • Basic metrics
  • Basic process monitoring
  • Default Cache/Surrogate Control headers
  • Default custom headers

Requirements

Node 6.0.0+

Installation

$ npm install

Usage

Look at the /example/app.js to see an example of how this can be pulled in as a dependency. You can see it running by doing the following.

$ PORT=5000 node example/app.js
info Server running at http://0.0.0.0:5000
info Server name: testHarness
info Server version: 0.1.0
info Server maxListeners: 1000
info Server environment: development
info Server in debug mode: true
160915/014027.438, [ops] memory: 65Mb, uptime (seconds): 5.705, load: [1.30322265625,1.486328125,1.5888671875]
160915/014032.438, [ops] memory: 58Mb, uptime (seconds): 10.706, load: [1.35888671875,1.49462890625,1.5908203125]

You can also navigate to localhost:5000 and see a served page.

Swagger documentation - localhost:5000/documentation

Healthcheck monitoring - localhost:5000/__health

Testing

$ cd <cnn-hapi-root> $ npm run example-server This will run the example server in the ./example directory.

ENV VARS

  • LOADER_IO_VALIDATION

  • PORT

  • LOCAL_TLS_PORT

  • CACHE_CONTROL

  • ENVIRONMENT

  • HOST

  • DEFAULT_MAX_LISTENERS

  • SURROGATE_CACHE_CONTROL

  • SHOW_CNN_HAPI_CONFIG => Setting this to 'true' will show server instance configurations on server.start(). Requires DEBUG=cnn-hapi* to be a part of DEBUG capture group

  • METRICS_FLUSHEVERY

serverInstance(options)

The following options set defaults at the server level and can override CNN-Hapi Defaults Populate notes are in order of priority. Example: populate: process.env.SOMEVALUE || options.someValue. In that example if process.env.SOMEVALUE is not set it will default to options.someValue, etc, etc Manual override possibilites are expressed in options.someValue

options is an object that can take the following keys

  • basePath: project basePath,

  • cacheControlHeader: process.env.CACHE_CONTROL || 'max-age=60',

  • customHeaders: options.customHeaders || [],

  • description: options.description || package.json description key,

  • environment: process.env.ENVIRONMENT || process.env.NODE_ENV || options.environment || '',

  • healthChecks: options.healthChecks || [],

  • host: process.env.HOST || options.host || '0.0.0.0',

  • loaderIoValidationKey: options.loaderIoValidationKey || undefined,

  • localTLS: options.localTLS || null,

  • maxListeners: process.env.DEFAULT_MAX_LISTENERS || options.maxListeners || 10,

  • name: options.name || package.json name key,

  • port: process.env.PORT || options.port || 3000,

  • surrogateCacheControl: process.env.SURROGATE_CACHE_CONTROL || options.surrogateCacheControl || 'max-age=360, stale-while-revalidate=60, stale-if-error=86400',

  • version:options.version || package.json version key,

  • withGoodConsole: options.withGoodConsole || false,

  • withSwagger: options.withSwagger || false

Override caching on individual routes

Using the reply.header() function can set headers on a singular route

{
    method: 'GET',
    path: '/override-headers',
    handler: (request, reply) => {
      reply('Peep the response headers in swagger docs')
      .header('Cache-Control', '2')
      .header('Surrogate-Control', 'baz');
    },
    config: {
      description: 'Example route for demonstrating how to  override headers by route',
      tags: ['api']
    }
  },

For explicit usage check this implementation in ./example/routes

Test

$ npm run example-server

It runs example server located in ./example. Pass in ENV vars through the above command or hardcode into the package.json located in the ./example directory.

Go to {HOST}:{PORT}/documentation to view the new swagger docs and to test current CNN-Hapi logic.