In this tutorial, you’ll learn a quick tip on how to debug Node Express project from visual studio code.
Let’s start by creating a simple Express web app. Create a folder called basicExpress. Navigate to the folder and initialize the Node project.
mkdir basicExpress
cd basicExpress
npm init
Once you have the project created, create a file called app.js. You’ll be using express framework, so install express using npm.
# install express using npm
npm install express --save
Add the following code to app.js .
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('How to Debug Node Express App !')
});
app.listen(port, () => console.log(`Example app listening on port ${port}!`))
Debug Node Express Project From Visual Studio Code
Now go to the Debug option in Visual Studio Code and click on the Start Debugging option.
Now the application will be running at http://localhost:3000 in debug mode. Add a breakpoint inside / route inside app.js code.
When the / route gets hit the break point will come into action and you can debug your code.