Giter Site home page Giter Site logo

response's Introduction

Node response

A package that helps debug in a more readable manner, by logging logged error and success message in the terminal in a well-formatted manner, which aids readability and helps in the separation of different logged responses as well as returning server success and error message in a general format throughout your codebase

Getting Started

This instructions will get you started on how to use this package.

Dependencies

  • Nodejs
  • npm (node package manager)

Install via NPM

 npm install v-response to install dependency

Usage

const response = require ("v-response");

To log an error or success message ("tag",value)

response.log("this is an error: ", payemnterror);
response.log("payment successful: ", payemntsuccessful);

    -------------------------------------------------------------------------------
          this is an error: paymenterror
    -------------------------------------------------------------------------------
    
    
    -------------------------------------------------------------------------------
          payment successful: payemntsuccessful
    -------------------------------------------------------------------------------

To return an error or success message from the server

app.get("/", (req, res) => {
    let age = 1;
    if (age < 2) {
        return res.status(200)
            .json(response.ApiResponse(true, 200, "yes age is less than 2", age));
    }else {
        return  res.status(400)
            .json(response.ApiResponse(false,400,"no age is not less than 2",undefined,error));
    }

})

To generate random Numbers either numeric or alphanumeric

app.get("/generate_opt",(req,res) => {
//expecting two callback (size,true | false)

//if set to true numbers and letters will be generated

//if set to false only numbers will be generated 

let Otp = response.generateOTCode(6,false);
response.log("OneTimePassword: ",Otp);

})

Result

 -------------------------------------------------------------------------------
          OneTimePassword: 234574
    -------------------------------------------------------------------------------

To sign Jwt Token

let Generate_jwt = response.signToken(payload,secret);
response.log("Jwt token:",Generate_jwt);

Result

------------------------------------------------------------------------------
Jwt token:      eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjVlNTY1NWJlNzJkODVhMDk1MDUyNWFhOCIsImlhdCI6MTU4Mjc5MjQ1NX0.niULywaPIaF01vBNpgNaCeerSJt8xW3vlRWlqkmn0sQ
-------------------------------------------------------------------------------

To hash password

     let _hash_password =  response.hashedPassword(req.body.password, 10);
     response.log("Hashed password:",_hash_password);

Result

-------------------------------------------------------------------------------
Hashed password: $2a$10$RwaB/O4KUm5tw6VIvVlNMeFblya1fEut4pHeWbvCkw9i/K.cl8iru
-------------------------------------------------------------------------------

Author

  • tycodez

response's People

Contributors

waletayo avatar

Stargazers

 avatar

Watchers

 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.