Code Monkey home page Code Monkey logo

error-auth-npm-package's Introduction

Authentication, Authorization and Errors Middleware Package for Node/Express

This package is for Nodejs and Express backend development to handle errors

Installation

Install the package with npm.

  npm install @ticketifyorg/common

Ignore any "Express-validator" or deprecation errors you might see on your terminal.

Quick Set-up

In the "app.js" or "Index.js" file of your project root,

Import errorHandler using whichever module method.

const {errorHandler} = require("@ticketifyorg/common");

OR

import {errorHandler} from "@ticketifyorg/common";

Then use the errorHandler at the very END of your root project after the app.listen() like this

e.g app.use(errorHandler);

Now, test the errorHandler if it works by creating an app.all router by importing the NotFound error module so the top of your project looks like this

const { errorHandler, NotFoundError } = require("@ticketifyorg/common");

Create the App.all router calling the NotFoundError()

app.all("*", (req, res) => { throw new NotFoundError() })

If you installed everything properly and hit an unknown route on your localhost, you should see a 'Route not found' error on your browser.

Enjoy and access the rest of the Documentation here.

Screenshots

App Screenshot

Signing In and Signing Up validation Set-up

This package works with express-validator package to help validate your Sign In and Sign Up post request.

To get started, all you have to do is import

const { body } = require("express-validator");

&

const { validateRequest } = require("@ticketifyorg/common");

to the top of your project.

NOTE: if you already have @ticketifyorg/common package installed, you DONT need to install the express-validator package.

Chain your Sign-Up/Sign-In endpoint buy passing the validator chain as a middleware. See Express-validator docs here.

After chaining up your middleware, all you have to do is pass in the validateRequest middleware in the router like in the screenshot below.

Screenshots

App Screenshot

Authors

Contributing

Contributions are always welcome!

Please adhere to this project's code of conduct.

error-auth-npm-package's People

Contributors

bigveezus avatar

Stargazers

John Rasine Irem avatar  avatar Wisdom avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.