Open In App

How to remove debugging from an Express app ?

Last Updated : 30 Nov, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will learn how to remove debugging or disable express debug logs from express applications. Express logs information about route matches, middleware functions in use, application mode, and the request-response cycle’s flow using the debug module internally. 

Debug logs do not need to be commented out in production code, unlike console.log, which is an enhanced version of that file. The DEBUG environment variable can be used to enable logging, which is disabled by default optionally.

Step 1: Go to your project directory and enter the following command to create a NodeJs project. Make sure that NodeJs is installed in your machine.

npm init -y

It will create a package.json file.

Step 2: Install two dependencies using the following command.

npm install express nodemon

Project Structure: It will look like the following. 

Project Structure

Step 3: Write the following code in app.js file. 

app.js

Javascript




const express = require('express')
const app = express()
const port = 3000
  
app.get('/', (req, res) => {
    console.log("Hello World");
})
  
app.listen(port, () => {
    console.log(`Example app listening on port ${port}`)
})


Step 4: Set the DEBUG environment variable to express to make use of this module while the express app is running:

$ DEBUG=express:* node app.js

On Windows, we need to use this below command,

> set DEBUG=express:* & node app.js

Output: After running this command in the express application, it will print the output like this:

 

Step 5: Now, If we make any request in this debug mode, this will log all information about the request and its response as well. We want to remove debug mode in our express application. So, we need to use the simple command in our command prompt for disabling express debug logs in the console. Use the below command for removing debug mode from our express application:

set DEBUG=myserver:app node server.js

Output:

 


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads