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

express-advanced-routing

v0.0.3

Published

Advanced routing helper for express.js

Downloads

3

Readme

ExpressAdvancedRouting

Advanced routing helper for express.js

Description

Its a simple module to make it easier to get your routing files using express.js. With this, you can require recursively and pass your params.

Installation

npm install express-advanced-routing --save

Syntax

routing(paths, router, params);
  • paths: It can be a string or an array with target paths. Path syntaxes:
    • Without file extension: '.app/index'
    • With file extension: '.app/index.js'
    • All files in the target folder: '.app/controllers/*'
    • All files in the target folder and recursively in every subfolders: '.app/controllers/**'
  • router: The router object used in the express app
  • params: (Optional) : If you want to add more params to pass to your routing files. It can be usefull with other initialized handlers.

Example:

Project structure

  • [project root]/
    • controllers/
      • services/
        • private/
          • security.js
        • rest.js
        • export.js
      • domain/
        • users/
          • list.js
          • show.js
          • edit.js
        • books/
          • read.js
        • base.js
      • main.js
    • index.js

Code

./index.js

'use strict';

var express = require('express'),
	routing = require('express-advanced-routing');

var app = express(),
	router = express.Router();

// require the main.js file under the controllers map and
// all js files under the controllers/domain, recursively
routing([ './app/controllers/main', './app/controllers/domain/**' ], router);

// It also require all files beneath the service folder and
// passing params object with one attribute: targetUrl
routing('./app/controllers/services/*', router, { targetUrl: '/endpoints'});

app.use('/', router);

app.listen(3000, () => {
	console.log('Server listening on port 3000');
});

./app/controllers/main.js

'use strict';

module.exports = (router) => {
	router.get('/', (req, res) => {
		res.render('main/index');
	});
};

./app/controllers/services/export.js

'use strict';

module.exports = (router, params) => {
	console.log(params.targetUrl); // => '/endpoints'

	router.get(params.targetUrl, (req, res) => {
		res.render('services/export');
	});
};

etc...

Included list:

  • ./app/controllers/main.js
  • ./app/controllers/domain/base.js
  • ./app/controllers/domain/users/list.js
  • ./app/controllers/domain/users/show.js
  • ./app/controllers/domain/users/edit.js
  • ./app/controllers/domain/books/read.js
  • ./app/controllers/services/rest.js
  • ./app/controllers/services/export.js

Future plans:

  • Excluding paths or single files
  • Minor improvements and small feature implementations