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

route-creator

v1.0.3

Published

Route generator for node applications to enforce modular structure

Downloads

4

Readme

route-creator

Framework agnostic auto generator of routes for node application based on application folder structure. Forces developers to follow a sensible modular structure for their node applications. Compatible with Express, Restify and Hapi (tested these so far).

Why route-creator

route-creator is NOT a framework. Its a utility to help you organize your code better and promote modularization.

Node applications typically have the following components but even the popular frameworks like express, restify, hapi etc. don't provide enough guidance to structure an application. route-creator provides one way to structure your applications. I'll add more ways down the road.

The approach that route-creator takes it is pretty simple. You just create your code artifacts as you please following a few simple rules. The route-creator will generate the routes and register them with your server. Currently, it generates both GET and POST routes and that should be okay for most applications. I will add a way to specify the method later.

Usage

  1. All modules should have a single folder at their root. That's the app_modules folder directly under the application root folder.
  2. All modules deserve their own folders. So, if you're creating a booking module, create a folder booking (under the app_modules folder, duh). Create a controllers folder under booking.
  3. Create a separate controller file for each route you want to handle. Eg: under booking, say you want create, delete and view routes. So, create 3 files that have the handler function for each of these routes. Name the files according to the functions - create.js, delete.js, view.js.
  4. Create a small config object in each file to identify the handler function (since you would probably create some helper functions in that file too) and any arguments for the route. module.exports this config object from that controller.
  5. require route-creator in your node application (check examples for code samples)
    var routeCreator = require('route-creator'); routeCreator.createRoutes(server);

After you create the folder structure and files as above, the app structure will look something like this:
<application_root>/app_modules/booking/controllers/view.js
<application_root>/app_modules/booking/controllers/delete.js
<application_root>/app_modules/booking/controllers/create.js

route-creator frees you up from having to specify routes separately and figures out the route based on the folder names and controller file names. For the above example, the routes created would be:
/booking/view
/booking/delete
/booking/create

Every controller file also needs a small config section.

config section

Provide a small JSON config object. There are just 2 attributes needed:

  • main(mandatory): The name of the main route handler function for the controller.
  • args(optional): Specify any arguments for the route.

Check the example to see in action.

Limitations

  • Reads only 1 folder level deep into the app_modules. It processes controllers folders that are only 2 levels under app_modules. Deeper nesting of modules is not supported currently, but planned.
  • Adds only GET and POST routes for all controllers with no dev options to change this behavior. More flexibility and options for specifying method are in the works.