1.3.2 • Published 2 years ago
@atz3n/express-utils v1.3.2
express-utils
A utilities library for express servers
Installation
npm install @atz3n/express-utils
you also have to have body-parser
, express-async-errors
and express-validator
installed.
npm install body-parser express-async-errors express-validator
Add 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 500
It 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 client
Have a look into the test server for example usage.
Development
To initialize the project just clone this repository and run
npm install
For linting run
npm run lint
You can try to autofix lint errors with
npm run lint:fix
For unit tests run
npm test