param2doc

0.0.1 • Public • Published

#param2doc

Express middleware to automatically map routing parameters onto Mongoose documents

##Installation

$ npm install param2doc

##Usage

###Example

var express = require('express');
var param2doc = require('param2doc');
var app = express();

var mongoose = require('mongoose');
mongoose.connect('mongodb://localhost/test');

var exampleSchema = mongoose.Schema({
  name: String
});

mongoose.model('Example', exampleSchema);

param2doc.init({mongoose: mongoose});

app.get("/path/:example", param2doc(), function (req, res) {
  if (req.documents.example)
    res.send("<h1>" + req.documents.example.name + "</h1>");
  else
    next();
});

When called with the URL http://server/path/0123456789ABCDEF then req.documents.example will contain a referemce to a document of the Example model with the ID 0123456789ABCDEF (if it exists).

##TODOs / Future features

  • Support app.params()
  • For more see TODOs in source code

Readme

Keywords

none

Package Sidebar

Install

npm i param2doc

Weekly Downloads

0

Version

0.0.1

License

MIT

Last publish

Collaborators

  • rotora