Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

express-route-builder

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-route-builder

Quickly compile Express.js routes with minimal code.

  • 0.0.6
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
26
increased by2500%
Maintainers
1
Weekly downloads
 
Created
Source

Express-Route-Builder

Quickly compile Express.js routes with minimal code.

NOTE: Requires Node.js v6.x

Quick Use

index.js

Setup your Express app as usual. It's a good idea to create a separate module to handle the building of your routes so as to keep your index.js minimal.

const express = require('express');
const app = express();
const routes = require('./routes');

routes.setup(app);
routes.js

Specify the module filenames that will handle each path with the .addRoute() method.

const path = require('path');
const express = require('express');
const ExpressRouteBuilder = require('express-route-builder');

module.exports.setup = function (app) {
  const baseDir = path.join(__dirname, 'controllers/');
  const builder = new ExpressRouteBuilder(express, app, baseDir);

  builder.addRoute('/comments', 'comments');
  builder.addRoute('/users', 'users');
};
controllers/comments.js (etc)

In each of the route modules you should specify functions named after the HTTP methods you want to expose. You can use any of the HTTP methods that Express supports, including:

get, post, put, head, delete, options, trace, copy, lock, mkcol, move, purge, propfind, proppatch, unlock, report, mkactivity, checkout, merge, m-search, notify, subscribe, unsubscribe, patch, search, connect

Note: The function names must be lowercase.

module.exports.get = function (req, res, next) { ... };
module.exports.post = function (req, res, next) { ... };
// ...and so on.

API

new ExpressRouteBuilder(express, app, baseDir = process.cwd());

Creates a new instance of the builder. The base directory is optional and defaults to the current working directory of your app.

.addRoute(path, filename, middleware = []);

Adds a route to your Express app based on the path given; you can specify any path that Express accepts. The filename should be the name of the module which will handle this route, relative to the base path given in the constructor. Also, you can optionally specify an array of middleware functions to use before the route is processed.

Keywords

FAQs

Package last updated on 05 May 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc