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

dp6-base-hapi

v1.2.11

Published

A base hapi configuration for my new API projects

Downloads

11

Readme

dp6LibBaseHapi CircleCI

A base hapi configuration for my new API projects

Pre-Requisites

  1. node 8.10 or greater
  2. npm 6.1.0 or greater
  3. redis 4.0 or greater

Usage

const baseConfig = require('base-hapi');
(async () => {
	const server = await baseConfig;
	await server.start();
	console.log(`Server started at ${server.info.uri}`);
	// server started at http://localhost:4000
})();

If you want to change the HOST and PORT you can do it by setting up two variable environments

HOST=192.168.1.25
PORT=2000

Configuration

Out of the box base-hapi comes with many defaults:

  1. Catbox Redis with the following configuration
{
  name: process.env.CATBOX_REDIS_NAME || 'catbox-redis',
  // engine: require(catbox-redis),
  partition: process.env.CATBOX_PARTITION_NAME || 'cache',
  host: process.env.REDIS_HOST || 'localhost',
  port: process.env.REDIST_PORT || 6379,
},
  1. Sentry for logging management. You will need an account here Now you can pass your sentry environment and dsn with these environment variables
options: {
  environment: process.env.NODE_ENV,
  dsn: process.env.SENTRY_DNS,
},
  1. For authentication you must define a function with your logic inside of it.
async function validate(token) {
  // your custom validation here
  // return true to pass to the handler
  // return false to return a 401 to client
  // credentials can be used inside your handlers in the request object
  // request.auth.credentials
  return { isValid: true, credentials: { id: 1 } };
}

const server = await baseConfig({ validate });
  1. Adding plugins
const myPlugin = {
  name: 'my-plugin',
  register(server) {
    server.route({
      handler() {
        return 'I am a plugin';
      },
      method: 'GET',
      path: '/my-plugin',
    });
  },
  version: '1.0.0',
};
const plugins = [myPlugin];
const server = await baseConfig({ plugins });
  1. The objection-paginate plugin is included.
const server = await baseConfig();
server.route({
  method: 'GET',
  path: '/pagination',
  handler(request, h) {
    return h.paginate({ results: [], total: 20 }, request.query);
  },
});

If you do not specify a limit in the query parameters it will use the OFFSET_DEFAULT environment variable

OFFSET_DEFAULT = 10