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

base-routes

v1.0.1

Published

Plugin for adding routes support to your `base` application. Requires templates support to work.

Downloads

100,513

Readme

base-routes NPM version NPM monthly downloads NPM total downloads Linux Build Status

Plugin for adding routes support to your base application. Requires templates support to work.

(TOC generated by verb using markdown-toc)

Install

Install with npm:

$ npm install --save base-routes

Usage

Register the plugin with your base application.

var routes = require('base-routes');
var Base = require('base-app');

var app = new Base();
app.use(routes());

API

.Router

The Router and Route classes are on the app instance, in case they need to be accessed directly.

Example

var router = new app.Router();
var route = new app.Route();

.handle

Handle middleware method for the given file.

Params

  • methodName {String}: Name of the router method to handle.
  • file {Object}: View object
  • next {Function}: Callback function
  • returns {undefined}

Example

app.handle('methodName', file, next);

.handleOnce

Run the given middleware handler only if the file has not already been handled by method.

Params

  • method {Object}: The name of the handler method to call.
  • file {Object}
  • returns {undefined}

Example

app.handleOnce(method, file, callback);
// example
app.handleOnce('onLoad', file, callback);

.route

Create a new Route for the given path. Each route contains a separate middleware stack. See the en-route API documentation for details on adding handlers and middleware to routes.

Params

  • path {String}
  • returns {Object}: Returns the instance for chaining.

Example

app.create('posts');
app.route(/blog/)
  .all(function(file, next) {
    // do something with file
    next();
  });

app.post('whatever', {path: 'blog/foo.bar', content: 'bar baz'});

.param

Add callback triggers to route parameters, where name is the name of the parameter and fn is the callback function.

Params

  • name {String}
  • fn {Function}
  • returns {Object}: Returns the instance for chaining.

Example

app.param('title', function(view, next, title) {
  //=> title === 'foo.js'
  next();
});

app.onLoad('/blog/:title', function(view, next) {
  //=> view.path === '/blog/foo.js'
  next();
});

.all

Special route method that works just like the router.METHOD() methods, except that it matches all verbs.

Params

  • path {String}
  • callback {Function}
  • returns {Object} this: for chaining

Example

app.all(/\.hbs$/, function(view, next) {
  // do stuff to view
  next();
});

.handler

Add a router handler method to the instance. Interchangeable with the handlers method.

Params

  • method {String}: Name of the handler method to define.
  • returns {Object}: Returns the instance for chaining

Example

app.handler('onFoo');
// or
app.handler(['onFoo', 'onBar']);

.handlers

Add one or more router handler methods to the instance.

Params

  • methods {Array|String}: One or more method names to define.
  • returns {Object}: Returns the instance for chaining

Example

app.handlers(['onFoo', 'onBar', 'onBaz']);
// or
app.handlers('onFoo');

About

Related projects

You might also be interested in these projects:

  • base: Framework for rapidly creating high quality node.js applications, using plugins like building blocks | homepage
  • en-route: Routing for static site generators, build systems and task runners, heavily based on express.js routes… more | homepage
  • gulp-routes: Add middleware to run for specified routes in your gulp pipeline. | homepage

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.

Building docs

(This project's readme.md is generated by verb, please don't edit the readme directly. Any changes to the readme must be made in the .verb.md readme template.)

To generate the readme, run the following command:

$ npm install -g verbose/verb#dev verb-generate-readme && verb

Running tests

Running and reviewing unit tests is a great way to get familiarized with a library and its API. You can install dependencies and run tests with the following command:

$ npm install && npm test

Author

Jon Schlinkert

License

Copyright © 2017, Jon Schlinkert. Released under the MIT License.


This file was generated by verb-generate-readme, v0.6.0, on August 07, 2017.