1.4.3 • Published 5 months ago
@atz3n/express-utils v1.4.3
express-utils
A utilities library for express servers
Installation
npm install @atz3n/express-utilsyou also have to have body-parser, express-async-errors and express-validator installed.
npm install body-parser express-async-errors express-validatorAdd the errorHandler function after your routes. Have a look into the test server for an example.
Content
The library contains the following throwable errors:
BadRequestError : returns status code 400
NotAuthorizedError : returns status code 401
NotFoundError : returns status code 404
InternalError : returns status code 500It also contains the following middleware functions:
validationRequest : validates express-validator validation results
validateAuthToken : validates an auth token
validateOrigin : validates the origin
errorHandler : sends error responses to the clientHave a look into the test server for example usage.
Development
To initialize the project just clone this repository and run
npm installFor linting run
npm run lintYou can try to autofix lint errors with
npm run lint:fixFor unit tests run
npm test