New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

expressjs-router

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expressjs-router

Structured routes for ExpressJS

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
5
increased by400%
Maintainers
1
Weekly downloads
 
Created
Source

Express Router

Structured routing for Express.JS

Example route.js

"use strict";


var MyModel = require("./models/MyModel");



function validate(req, res, next) {
  req.assert("id")
    .notEmpty().isInt();

  next(req, res, next);
}


function respond(req, res, next) {
  var id = req.param("id");
  
  MyModel.findById(id, function (error, instance) {
    if (error) {
      return req.json(500, { error: error.message });
    }
    else {
      res.json({ status: "OK", data: instance });
    }
  });
}



module.exports = {
  path: "/status/:id",
  method: "GET",

  validate : validate,
  respond  : respond
};

How to use with your express app

var express = require("express");
var expressRouter = require("expressjs-router");


var app = express();

expressRouter.create(app, "./path/to/routes");


app.listen(80);

Remarks:

  1. Routes prefixed by _ won't be included
  2. You can enable debug mode by calling expressRouter.enableDebug();

FAQs

Package last updated on 08 Feb 2014

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