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

express-mongoose-status

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

express-mongoose-status

A simple lib to handle mongoose responses and convert them to correct HTTP status in a REST API using Express

  • 0.0.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-66.67%
Maintainers
1
Weekly downloads
 
Created
Source

express mongoose status

This is a simple lib to handle mongoose responses and convert them to correct HTTP status in a REST API using Express

under continuous improvement....

Problems in common mongoose + express usage

Many code around the web, you can see something like this (when the err has error handler...):

route.get("/some/route/:id", function (req, res, next) {
  MongooseModel.find({"_id": req.params.id }, function (err, data) {
    if (err) {
      return res.status(500).send(err.name); //or next(err), res.sendStatus(500) etc
    }
    res.send(data);
  });
});

Whats the problem with follow approach?

  • Any kind of error will throws status 500 Internal Error
  • If the param.id isn't a ObjectId, it will throw a CastError (instead of 404 not found behavior)
  • Any ValidatorError error will not throws a expected 400 Bad Request
  • Even with valid ObjectId in param.id, successful, but empty responses will throw a 200 OK

Why not just abstract this? Why repeat yourself with a lot of validations? It can be so simple...

var statusHandler = require("express-mongoose-status");
route.get("/some/route/:id", function (req, res, next) {
  MongooseModel.find({"_id": req.params.id }, function (err, data) {
    statusHandler(err, res, data);
  });
});

Installation

npm install express-mongoose-status --save

To be added

  • Doc
  • Samples
  • Tests

Keywords

FAQs

Package last updated on 14 Apr 2015

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