Skip to content

Instantly share code, notes, and snippets.

@jhnns
Last active November 16, 2018 11:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhnns/5b5df60cefb33c6f593024b7e112db5e to your computer and use it in GitHub Desktop.
Save jhnns/5b5df60cefb33c6f593024b7e112db5e to your computer and use it in GitHub Desktop.
How to debug a Node.js server written in TypeScript running in Docker
version: "3"
services:
server:
command: npm run debug
build: .
volumes:
- ./dist/src:/server/dist/src/ # same folder structure on local machine and docker container
ports:
- "3001:3001" # open port for server api
- "9222:9222" # open port for inspector to debug
FROM node:10.8.0-alpine
WORKDIR /server
COPY package.json package-lock.json ./
RUN npm ci
COPY . /server
CMD [ "npm", "run", "start" ]
const gulp = require("gulp");
const ts = require("gulp-TypeScript");
const sourcemaps = require("gulp-sourcemaps");
const filter = require("gulp-filter");
const watch = require("gulp-watch");
const rimraf = require("rimraf");
const tsProject = ts.createProject("./tsconfig.json");
gulp.task("transpile", () => {
const tsResult = tsProject
.src()
.pipe(sourcemaps.init())
.pipe(tsProject(ts.reporter.fullReporter()))
.on("error", () => null);
return tsResult.js.pipe(sourcemaps.write("./")).pipe(gulp.dest("./dist/src"));
});
gulp.task("watch-server", ["transpile"], function() {
return watch(["src/**/*.{ts,tsx}"], function() {
gulp.start("transpile");
});
});
gulp.task("initial-clean", function(done) {
rimraf("./dist", done);
});
gulp.task("start-watch", ["initial-clean"], () => {
gulp.start("watch-server");
});
gulp.task("watch", ["start-watch"]);
{
"compilerOptions": {
"target": "es5",
"module": "commonjs",
"types": ["@types/node", "node"],
"typeRoots": ["./node_modules/@types"],
"lib": ["es5", "es6", "es2015"],
"rootDir": "src",
"outDir": "dist", // specify the directory for your compiled code
"experimentalDecorators": true,
"emitDecoratorMetadata": true,
"moduleResolution": "node"
},
"include": ["src/**/*.ts"],
"exclude": ["node_modules", "dist"]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment