api-response-formate is for simple and standard api response
npm install api-response-formate
-
res
- res: Response -
code
- Response status code. -
data
- response data -
message
- Message -
error
- error object
cosnt response =require('api-response-formate');
cosnt test=(req,res,next)=>{
try{
return response(res,200,'my data','success',null)
/**
API response will be --
{code: 200, data:'my data' ,message:'succsess',error:null}
*/
}catch(error){
return response(res,402,null,'Something went wrong..!',error);
/**
API response will be --
{code: 402, data:null,message:'Something went wrong..!',error: error object}
*/
}
}
module.exports=test