Posts

Showing posts with the label Errors

Node JS Convert 404 API Route to Proper Message

Image
We Generally Face A Problem of Bad Error Handling If Route Not Found in Node JS, Let's See How Can We Fix This Error Handling in Node JS Via adding below 4 lines code in our main node js file, we can manage it easily: //404 error handling app . use (( req , res ) => { const error = new Error ( "Not found." ) req . code = 1 req . statusCode = 404 ResponseMiddleware ( req , res , error . message ) }) That's it ! Happy Coding !