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

grand-central-junction

v0.1.0

Published

A simple, lightweight router for Node and Express

Downloads

4

Readme

Grand Central Junction

A simple Rails-inspired router for Node built on top of Express.

Documentation

route(app, options)

Options that can be specified:

  • dir -- the home directory of the app. Defaults to the directory that contains the node_modules folder
  • routes -- the routes path, relative to the directory route() is called from. Defaults to config/routes
  • controllers -- the controllers path. Defaults to controllers

In your app.js file or wherever you initialize your Express app, add the following code:

var express = require('express'),
    gcj = require('grand-central-junction'),
    app = express();

gcj.route(app);

With custom options:

gcj.route(app, {
    dir: __dirname + '/app',
    routes: 'router/routes',    // Will get the routes from ./app/router/routes.js
    controllers: 'controllers'  // Will look for controllers in ./app/controllers/
});

Routes.js

Example of /config/routes.js:

var oauth = require('../oauth');

match('/',         'home#index');
match('/user/:id', 'user#get');
match('/user',     'user#create', {via: 'post'});
put('/user/:id',   'user#update');
del('/user/:id',   oauth.requireAuth, 'user#remove');

resources('/animal', 'animal');

Routes:

GET    /            => /controllers/home.js#index
GET    /user/:id    => /controllers/user.js#get
POST   /user        => /controllers/user.js#create
PUT    /user/:id    => /controllers/user.js#update
DELETE /user/:id    => /oauth.js#requireAuth >> /controllers/user.js#remove

GET    /animal      => /controllers/animal.js#index
GET    /animal/:id  => /controllers/animal.js#show
POST   /animal      => /controllers/animal.js#create
PUT    /animal/:id  => /controllers/animal.js#update
DELETE /animal/:id  => /controllers/animal.js#destroy
GET    /animal/create     => /controllers/animal.js#create
GET    /animal/edit/:id   => /controllers/animal.js#update
GET    /animal/delete/:id => /controllers/animal.js#destroy

match(route, action, [options])

A GET route to the specified controller/action.

  • route string regex-- the Express routing string/RegEx
  • action string function -- either a direct callback with req, res params or a string in the format of 'controller#action', with controller being the name of the file in the controllers directory and action being the name of the method in the controller.
  • [options] object
    • via changes the method of the route: get (default), post, put, delete
    • method same as via

VERB(route, [action...], action)

Same as match() options above, but without options and the ability to include many actions. VERB = get|post|put|del|all

resources(route, [controller])

Maps all HTTP methods to their respective CRUD actions in a controller. The action names are the same as those in Rails with a few extras added in (see above list of routes for names).

  • route string regex -- the Express routing string/RegEx
  • controller string -- the name of the file in the controllers directory, so 'project' would be the name of ./controllers/project.js. This defaults to whatever name is in the route string.