xcore-express

A library that brings middlewares and helper functions to organize web applications using Node and Express.

npm install xcore-express
2 downloads in the last week
5 downloads in the last month

xcore

http://zmian.me

xcore is a library that brings middlewares and helper functions to organize web applications using Node and Express.

Guide

A reference guide to middlewares and helper functions included in xcore.

Exception Classes

Class NameDescriptionDefault Message
ExceptionThe exception that is thrown when an error occurs.No Description
ArgumentExceptionThe exception that is thrown when one of the arguments provided to a method is not valid.Invalid Argument
InvalidInputExceptionThe exception that is thrown when one of the input provided to a method is not valid.Invalid Input
NotImplementedExceptionThe exception that is thrown when a requested method or operation is not implemented.Not Implemented
NotSupportedExceptionThe exception that is thrown when a requested method or operation is not supported.Not Supported
NotFoundExceptionThe exception that is thrown when an attempt is made to find something that does not exist.Not Found
UnauthenticatedExceptionThe exception that is thrown when a requested method or operation requires authentication.Not Authenticated
UnauthorizedExceptionThe exception that is thrown when the current user is not allowed to perform an attempted operation.Not Authorized

Middlewares

ErrorHandler

A middleware to detect error type and send a JSON response with approperiate HTTP Status code and message.

Usage:

if (!req.isAuthenticated()) {
  throw new UnauthenticatedException("Authentication is required.");
}

Example response:

{
  "meta": {
    "code": 401,
    "success": false,
    "message": "Authentication is required."
  }
}
Logger

A middleware to format and log errors to console.

Sample console log:

>> GET /api/users/me
>> [UnauthenticatedException] Authentication is required.
>> [Error]
>> ... stack trace ...

Author

License

(The MIT License)

Copyright (c) 2013 Zeeshan Mian

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

npm loves you