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

scenic

v1.0.1

Published

Programmatically setup routes and resources for HapiJS server

Downloads

3

Readme

Scenic

A very hapi route auto-loader

Usage

Easily manage your HapiJS routes and resources by storing your basic route configurations in a designated routes folder.

Examples

  • Basic Example - Just a basic example usage
  • Advanced Example - Something a little more realistic, this is an example of how you can use Scenic with other plugins to load pretty much everything programmatically, such as the routes, controllers, configuration file and all other HapiJS plugins (via Confidence)

Under The Hood

There really isn't anything too fancy here. All this does is recursively iterate through the folder containing your routes, and load any of the exported configurations into Hapi as resources, but before doing so, the path to the file containing the resources will be appended to the path value in the resources themselves (relative to the routes folder)

Example

Lets say I create a file at `routes/hello.js, with the following content:

module.exports = [{
    method: 'GET',
    path: '/world',
    handler: function( request, reply ){
        return reply('Hello!')
    }
},{
    method: 'POST',
    path: '/world',
    handler: function( request, reply ){
        return reply('Thank you for your details')
    }
}]

This will create two resources:

  1. GET /hello/world
  2. POST /hello/world

Route Folder

By default, Scenic will look for a folder called /routes in the root of you project, but you can change this by defining routeDir in the plugin options when loading the plugin. As long as the value is a valid path to an existing folder, it should work fine.

Root Resource

Since the filename containing the resources is prepended to the route path within the path files, you will need to define which route file you want to use as your root resource, this will skip the modification of the path value in the resources. To do this, just add a rootResource value to the plugin options, and specify the file you wish to use (without the .js extension)

Debugging

If you want to know whats going on behind the scenes, then add a debug value to the options when loading Scenic, or in the configuration file. The value should be numeric:

  • 0 - No output (Same as null)
  • 1 - Errors only
  • 2 - Errors and information
  • 3 - Errors, information and debugging data

Note: If you install Chalk, then the output will be colorized.

Todo

  • Allow users to specify more than one rootResource file, skipping path modifications for all contained resources
  • Write unit tests (yeah yeah yeah, I know)