Debugging a Node.js application

We'll start with the easiest one—a Node.js application. We will use our sample application in folder ~/fod/ch06/node, which we worked with earlier in this chapter:

  1. Make sure that you navigate to this project folder and open VS Code from within it:
$ cd ~/fod/ch06/node$ code .
  1. In the terminal window, from within the project folder, run a container with our sample Node.js application:
$ docker container run --rm -it \   --name my-sample-app \   -p 3000:3000 \   -p 9229:9229 \   -v $(pwd):/app \   sample-app node --inspect= index.js

Note how I map port 9229 to the host. This port is used by the debugger, and VS Studio will communicate with our Node application via this port. Thus it is important that you open ...

Get Learn Docker - Fundamentals of Docker 19.x - Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.