https://github.com/pythoninthegrass/node_docker
POC for Node.js debugging in Docker and/or WSL + Docker Desktop.
https://github.com/pythoninthegrass/node_docker
Last synced: 11 months ago
JSON representation
POC for Node.js debugging in Docker and/or WSL + Docker Desktop.
- Host: GitHub
- URL: https://github.com/pythoninthegrass/node_docker
- Owner: pythoninthegrass
- Created: 2022-04-20T03:43:42.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2022-04-20T04:06:10.000Z (over 3 years ago)
- Last Synced: 2025-01-11T16:50:27.212Z (about 1 year ago)
- Language: JavaScript
- Size: 177 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# node-docker
**Table of Contents**
* [node-docker](#node-docker)
* [Setup](#setup)
* [Usage](#usage)
* [Debug in VSCode](#debug-in-vscode)
* [Further reading](#further-reading)
## Setup
* Start the Node.js app in Docker
```bash
# build the image
docker-compose build
# start the container in detached mode
docker-compose up -d
# tail the last 50 lines of logs
docker-compose logs -tf --tail="50" node-docker
```
## Usage
* Send a command
```bash
curl --request POST --url http://localhost:8000/test --header 'content-type: application/json' --data '{"msg": "testing" }'
```
## Debug in VSCode
* Select the Docker extension on the left-hand toolbar
* Under containers, right click the `node_docker_node_docker` (awkward, I know) container
* Attach Visual Studio Code > Hit enter to select the same container in the popup menu
* A new VSCode window appears inside of the Docker container root directory
* Selct Open Folder in Explorer on the left-hand column
* Choose `/app` as the directory

* Select the `server.js` file in Explorer on the left-hand side
* Run and Debug
* On the status bar at the bottom, select Run Current File
* Choose `Node.js...`
* Run Current File
* Set a breakpoint

## Further reading
[Build your Node image | Docker Documentation](https://docs.docker.com/language/nodejs/build-images/)
[Build and run a Node.js app in a container](https://code.visualstudio.com/docs/containers/quickstart-node)
[Debug Node.js Apps using Visual Studio Code](https://code.visualstudio.com/docs/nodejs/nodejs-debugging)
[Docker Node.js Example](https://gist.github.com/remarkablemark/a877f2d78bfac0e9aca003c99df137ee)