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=0.0.0.0 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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.