Working on nodejs_debug
parent
2d38e67524
commit
ee839ce4f6
39
nodejs_debug.md
Normal file
39
nodejs_debug.md
Normal file
@ -0,0 +1,39 @@
|
||||
# Debug nodejs in container
|
||||
|
||||
There are multiple ways of debugging within nodejs, from most manual one to utilize vscode `.devcontainer` feature
|
||||
|
||||
## Method 1: Manual start debugger
|
||||
|
||||
Checks there is a `launch.json` file within `.vscode`, with following conten
|
||||
|
||||
```json
|
||||
{
|
||||
"name": "Docker: Attach to Node.js",
|
||||
"type": "node",
|
||||
"request": "attach",
|
||||
"remoteRoot": "/work/src/",
|
||||
"port": 9229,
|
||||
"address": "localhost",
|
||||
"localRoot": "${workspaceFolder}/nodejs/src",
|
||||
"protocol": "inspector",
|
||||
"restart": true,
|
||||
},
|
||||
```
|
||||
|
||||
1. Make sure `CMD ["nodemon", "--inspect=0.0.0.0:9229", "./src/server.js"]` within dockerfile is commented out.
|
||||
2. Build and run nodejs container
|
||||
3. In a separate terminal, `docker exec -it nodejs sh` to attach shell to container.
|
||||
4. Manually start debugger process in container `nodemon --inspect=0.0.0.0:9229 ./src/server.js`
|
||||
5. In vscode debugger, select the debugger profile "Docker: Attach to Node.js", and start debugger by link to the port 9229
|
||||
6. Set breaker in the codes
|
||||
7. In Chrome, open `localhost:5502` to the open port
|
||||
8. Should notice that program will stop at breakpoint
|
||||
|
||||
## Method 2:
|
||||
|
||||
## Reading lists
|
||||
|
||||
* [VSCode DOC: Node.js in a container](https://code.visualstudio.com/docs/containers/quickstart-node)
|
||||
* [VSCode DOC: Launch versus attach configuration](https://code.visualstudio.com/Docs/editor/debugging#_launch-versus-attach-configurations)
|
||||
* [VSCode DOC: Remote debugging](https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_remote-debugging)
|
||||
* [VSCode DOC: Developing inside a container](https://code.visualstudio.com/docs/remote/containers)
|
Loading…
x
Reference in New Issue
Block a user