Debug Nodejs inside docker container

If you want to debug a node js or express application that is running inside a docker container please follow the below steps.

Step1:
  add pryjs in you package.json and run npm install
   or
  npm install --save pryjs

Step 2:
  Go to your docker-compose file and find the specific docker container which you want to debug.
  Ex. if your container name is an app then please add the below lines
  app:
    stdin_open: true
    tty: true

Step 3:
  Go the specific file where you want to debug and require the library
    var pry = require('pryjs');

  Then add the script to the specific like where you want to stop the execution.
    eval(pry.it)

Step 4:
  Run the docker compose file and attach the specific process
   docker-compose up -d && docker attach $(docker-compose ps -q app)

It will stop the execution in the specific line once the request will hit that specific line

Please check the documentation for a more pry option.

Comments

Popular posts from this blog

Insert Bulk data using active record import

Swap primary keys between two records in the same table in Postgres

How to add a bootstrap table with fixed header and scrollable body