try_catch_req

1.0.0 • Public • Published

try-catch

handling callbacks with async/await on node js server req,res pipeline without managing

try{ 
// the progrm that will cause exception 
}catch(){
// handling when the exception has happened
}

Just wrape your req,res pipeline with a tryCatch method by importing from this library, then it handles the rest.

Install the dependency

npm install try_catch_req

Example

const express=require('express');
const tryCatch=require('./index')
const app=express();

app.use(express.json())
app.post('/test',tryCatch(async(req,res,next)=>{
    const {name,job}=req.body;
    // you can call any async functions with await keyword,
    // Incase if exception throws that function the library handles automatically.
    res.status(201).json({message :`Well come ${name}, Are you really a ${job}?`})}));
module.exports=app;

Dependencies (0)

    Dev Dependencies (3)

    Package Sidebar

    Install

    npm i try_catch_req

    Weekly Downloads

    1

    Version

    1.0.0

    License

    ISC

    Unpacked Size

    1.94 kB

    Total Files

    3

    Last publish

    Collaborators

    • amareabewa