Skip to content

Latest commit

 

History

History
17 lines (10 loc) · 755 Bytes

File metadata and controls

17 lines (10 loc) · 755 Bytes

A Crude Debug Mode For a Dockerized NestJS App

Caution

Why I say crude? Because you need to write debugger and cannot use breakpoints :/.

  1. Create a Dockerfile as we did here.

    FROM node:20.10.0-slim AS development
    ENV PNPM_HOME="/pnpm"
    ENV PATH="$PNPM_HOME:$PATH"
    RUN corepack enable
    ARG NODE_ENV=development
    ENV NODE_ENV=${NODE_ENV}
    WORKDIR /usr/src/app
    COPY pnpm-lock.yaml .
    RUN pnpm fetch
    # COPY package*.json .
    EXPOSE 3000 9229
    COPY . .
    RUN pnpm install -r --offline

  2. Create and expose 9229 port in your compose file, see here.

    services:
    api:
    build:
    context: .
    target: development
    ports:
    - 3000:3000
    - 9229:9229
    volumes:
    - .:/usr/src/app
    - /usr/src/app/node_modules
    command: npm run start:debug

  3. Create launch.json.

    {
    "version": "0.2.0",
    "configurations": [
    {
    "type": "node",
    "request": "attach",
    "name": "Debug",
    "remoteRoot": "/usr/src/app",
    "localRoot": "${workspaceFolder}",
    "protocol": "inspector",
    "port": 9229,
    "restart": true,
    "address": "0.0.0.0",
    "skipFiles": ["<node_internals>/**"],
    "sourceMaps": true
    }
    ]
    }