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

socks-routes

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

socks-routes

A basic package for cleaning up some boilerplate behind express routes.

  • 1.0.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Socks-Routes

A basic package for cleaning up some boilerplate behind express routes.

Usage:

Usage is very simple! When initializing your app, you should add this to your express code:

./app.js:

var express = require('express');
var path = require('path');

[...] // Require your various other modules here

var routes = require('socks-routes');
var app = express();

[...] // Set up your app here, such as sessions and other middleware

// Load the routes
routes.loadDir(app, path.join(__dirname, 'routes'));

[...] // Any final routes and middleware, and app start-up

./routes/index.js

For the routes themselves, I've boiled it down to a one-liner of boilerplate:

// Simple one-line drop in replacement for express's default route
//  boilerplate, that specifies the route for `/`
var router = module.exports = require('socks-routes').Route('/');

// The rest is the same as express's default route skeleton

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express' });
});

Note that, as with bare express routes, you can specify multiple routers that can handle the same route if you feel that certain aspects of your app make more sense in separate files.

Socks-Routes will grab all the javascript routes in ./routes and its subdirectories and load them into the app. No more having to manually require and app.use() each and every route, they and their relevant information are tucked away in one convenient file for you to modify as your needs change.

Keywords

FAQs

Package last updated on 03 Jan 2018

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