DEV Community

Mitesh Kamat
Mitesh Kamat

Posted on

2

Debugging node js app

Introduction

Almost every javascript page that we create can be debugged on browser.
We debug code for fixing any defect or to have a better code understanding. So, I was wondering what about node js. Can I inspect my nodejs app or express app?

I somehow didn't pay attention to this and used to write log statements inside my express app. Then, I referred node js official doc
https://nodejs.org/en/docs/guides/debugging-getting-started/

Steps:
1) Run your node js application using --inspect flag like
node --inspect filename.js

It shows
Debugger listening on ws://127.0.0.1:9229/3da188c5-8ab4-41e6-9fb2-2871638cb657
For help see https://nodejs.org/en/docs/inspector
App is listening on port 5000
Debugger attached.

2) Open a new tab in chrome and type about:inspect

3) Locate your file of interest under remote target.

4) click on “Open dedicated DevTools for Node” to start debugging.

The official doc also shows handy command line options.

That's it .. Enjoy debugging !!!!

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay