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 - npm Package Compare versions

Comparing version 1.1.2 to 1.1.3

2

package.json
{
"name": "expressjs-router",
"version": "1.1.2",
"version": "1.1.3",
"description": "Structured routes for ExpressJS",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,3 +0,3 @@

Express Router
==============
Express.js Router [![Build Status](https://travis-ci.org/olivierkaisin/express-router.png?branch=master)](https://travis-ci.org/olivierkaisin/express-router)
=================

@@ -7,20 +7,41 @@ Structured routing for **Express.JS**

### Example `route.js`
## Example
Project structure:
```
.
+-- routes
| +-- getStatus.js
+-- models
| +-- MyModel.js
+-- app.js
```
### Route definition `getStatus.js`
```javascript
// File: ./routes/getStatus.js
"use strict";
var MyModel = require("./models/MyModel");
var MyModel = require("../models/MyModel");
function validate(req, res, next) {
// The synchronous validate function is executed before the responder, allowing
// to easily check for the existence of parameters and their format.
//
// If a parameter doesn't follow the specification, the router will automatically
// respond with an HTTP 400 status and output validation errors in a JSON.
function validate(req, res) {
req.assert("id")
.notEmpty().isInt();
next(req, res, next);
}
// The respond method is the actual implementation of our route
function respond(req, res, next) {

@@ -41,2 +62,7 @@ var id = req.param("id");

// The exports describe the route definition.
// .path, .method and .respond are required
//
// Conditions are checked to define wether the route should be
// executed or not. You can define as many conditions as you want.
module.exports = {

@@ -46,11 +72,17 @@ path: "/status/:id",

validate : validate,
respond : respond
validate : validate,
respond : respond,
conditions : ["loginRequired"]
};
```
### Express `app.js`
### How to use with your express app
```javascript
// File: ./app.js
```javascript
"use strict";
var express = require("express");

@@ -62,2 +94,12 @@ var expressRouter = require("expressjs-router");

// By enabling debug mode, routes will be logged to stdout
expressRouter.enableDebug();
// This conditional will allow us to require login on routes
expressRouter.createConditional("loginRequired", function (req, res) {
return !!req.user;
});
// We finally create our routes by giving the path where they are stored
expressRouter.create(app, "./path/to/routes");

@@ -74,1 +116,6 @@

2. You can enable debug mode by calling `expressRouter.enableDebug();`
### License:
MIT
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