Last active
November 16, 2018 11:56
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM node:10.8.0-alpine | |
WORKDIR /server | |
COPY package.json package-lock.json ./ | |
RUN npm ci | |
COPY . /server | |
CMD [ "npm", "run", "start" ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Show hidden characters
{ | |
"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