<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>remote debugger &#8211; Best DevOps</title>
	<atom:link href="https://www.bestdevops.com/tag/remote-debugger/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.bestdevops.com</link>
	<description>Lets Learn, Do it &#38; Share! Thats a Best DevOps!!!</description>
	<lastBuildDate>Mon, 12 Oct 2026 04:18:44 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1.3</generator>
	<item>
		<title>How to Use TypeScript &#038; Docker to Build a REST Service with Debugging</title>
		<link>https://www.bestdevops.com/how-to-use-typescript-docker-building-a-rest-service/</link>
					<comments>https://www.bestdevops.com/how-to-use-typescript-docker-building-a-rest-service/#respond</comments>
		
		<dc:creator><![CDATA[anil]]></dc:creator>
		<pubDate>Tue, 15 Nov 2016 07:58:17 +0000</pubDate>
				<category><![CDATA[IT Training]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Docker Building]]></category>
		<category><![CDATA[nodemon]]></category>
		<category><![CDATA[remote debugger]]></category>
		<category><![CDATA[TYpeScript]]></category>
		<guid isPermaLink="false">http://www.bestdevops.com/?p=62</guid>

					<description><![CDATA[Learn how to combine TypeScript and Docker to build a production-ready REST service, complete with debugging support for IDEs like WebStorm and VSCode.]]></description>
										<content:encoded><![CDATA[
<h1 class="wp-block-heading">How to Use TypeScript &amp; Docker to Build a REST Service with Debugging</h1>



<p class="wp-block-paragraph">TypeScript and Docker are a powerful combination for building reliable, maintainable REST services. TypeScript brings static typing and modern JavaScript features to your Node.js backend, while Docker ensures your service runs consistently across development, staging, and production environments. This guide explains how to wire the two together, including setting up remote debugging from IDEs such as WebStorm and Visual Studio Code.</p>



<h2 class="wp-block-heading">Why Combine TypeScript and Docker for REST Services?</h2>



<p class="wp-block-paragraph">Running a TypeScript REST service inside Docker solves several common DevOps pain points:</p>



<ul class="wp-block-list">
  <li><strong>Reproducible builds:</strong> The TypeScript compilation step is baked into the Docker image, so every environment uses exactly the same compiled output.</li>
  <li><strong>Dependency isolation:</strong> Node modules are installed inside the container, eliminating &#8220;works on my machine&#8221; problems caused by differing local <code>node_modules</code> trees.</li>
  <li><strong>Type safety at build time:</strong> TypeScript catches type errors during the Docker build step, preventing broken images from being deployed.</li>
  <li><strong>Scalability:</strong> Containerised services are straightforward to orchestrate with Docker Compose, Kubernetes, or any container platform.</li>
</ul>



<h2 class="wp-block-heading">Project Structure</h2>



<p class="wp-block-paragraph">A typical TypeScript REST service prepared for Docker looks like this:</p>


<pre class="wp-block-code"><span><code class="hljs language-php">my-rest-service/
├── src/
│   ├── index.ts          <span class="hljs-comment"># Entry point</span>
│   └── routes/
│       └── health.ts     <span class="hljs-comment"># Example route</span>
├── dist/                 <span class="hljs-comment"># Compiled JS output (generated)</span>
├── tsconfig.json
├── package.json
├── Dockerfile
└── docker-compose.yml</code></span></pre>


<h2 class="wp-block-heading">TypeScript Configuration</h2>



<p class="wp-block-paragraph">A minimal <code>tsconfig.json</code> suitable for a Node.js REST service:</p>


<pre class="wp-block-code"><span><code class="hljs language-json">{
  <span class="hljs-attr">"compilerOptions"</span>: {
    <span class="hljs-attr">"target"</span>: <span class="hljs-string">"ES2020"</span>,
    <span class="hljs-attr">"module"</span>: <span class="hljs-string">"commonjs"</span>,
    <span class="hljs-attr">"outDir"</span>: <span class="hljs-string">"./dist"</span>,
    <span class="hljs-attr">"rootDir"</span>: <span class="hljs-string">"./src"</span>,
    <span class="hljs-attr">"strict"</span>: <span class="hljs-literal">true</span>,
    <span class="hljs-attr">"esModuleInterop"</span>: <span class="hljs-literal">true</span>,
    <span class="hljs-attr">"sourceMap"</span>: <span class="hljs-literal">true</span>
  },
  <span class="hljs-attr">"include"</span>: &#91;<span class="hljs-string">"src"</span>]
}</code></span></pre>


<p class="wp-block-paragraph">Setting <code>"sourceMap": true</code> is essential for debugging inside Docker — it allows the debugger to map minified or compiled JavaScript back to the original TypeScript source files.</p>



<h2 class="wp-block-heading">Writing a Simple REST Entry Point</h2>



<p class="wp-block-paragraph">The following example uses Express, one of the most common Node.js HTTP frameworks:</p>


<pre class="wp-block-code"><span><code class="hljs language-javascript"><span class="hljs-comment">// src/index.ts</span>
<span class="hljs-keyword">import</span> express, { Request, Response } <span class="hljs-keyword">from</span> <span class="hljs-string">'express'</span>;

<span class="hljs-keyword">const</span> app = express();
<span class="hljs-keyword">const</span> PORT = process.env.PORT || <span class="hljs-number">3000</span>;

app.use(express.json());

app.get(<span class="hljs-string">'/health'</span>, (_req: Request, <span class="hljs-attr">res</span>: Response) =&gt; {
  res.json({ <span class="hljs-attr">status</span>: <span class="hljs-string">'ok'</span> });
});

app.listen(PORT, () =&gt; {
  <span class="hljs-built_in">console</span>.log(<span class="hljs-string">`Server running on port <span class="hljs-subst">${PORT}</span>`</span>);
});</code></span></pre>


<h2 class="wp-block-heading">Dockerfile</h2>



<p class="wp-block-paragraph">A multi-stage Dockerfile keeps the final image small by discarding the TypeScript compiler and development dependencies before producing the production image:</p>


<pre class="wp-block-code"><span><code class="hljs language-php"><span class="hljs-comment"># Stage 1 – build</span>
FROM node:<span class="hljs-number">20</span>-alpine <span class="hljs-keyword">AS</span> builder
WORKDIR /app
COPY package*.json ./
RUN npm ci
COPY tsconfig.json ./
COPY src ./src
RUN npm run build

<span class="hljs-comment"># Stage 2 – production image</span>
FROM node:<span class="hljs-number">20</span>-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --omit=dev
COPY --from=builder /app/dist ./dist
EXPOSE <span class="hljs-number">3000</span>
CMD &#91;<span class="hljs-string">"node"</span>, <span class="hljs-string">"dist/index.js"</span>]</code></span></pre>


<p class="wp-block-paragraph">Ensure your <code>package.json</code> includes a build script that invokes the TypeScript compiler:</p>


<pre class="wp-block-code"><span><code class="hljs language-json">{
  <span class="hljs-attr">"scripts"</span>: {
    <span class="hljs-attr">"build"</span>: <span class="hljs-string">"tsc"</span>,
    <span class="hljs-attr">"start"</span>: <span class="hljs-string">"node dist/index.js"</span>,
    <span class="hljs-attr">"dev"</span>: <span class="hljs-string">"ts-node src/index.ts"</span>
  }
}</code></span></pre>


<h2 class="wp-block-heading">Docker Compose for Local Development</h2>



<p class="wp-block-paragraph">During development you typically want live reloading and a debug port exposed. A <code>docker-compose.yml</code> configured for this looks like:</p>


<pre class="wp-block-code"><span><code class="hljs language-php">version: <span class="hljs-string">'3.8'</span>
services:
  api:
    build:
      context: .
      target: builder          <span class="hljs-comment"># Use the build stage so devDeps are available</span>
    volumes:
      - ./src:/app/src         <span class="hljs-comment"># Mount source for live edits</span>
    ports:
      - <span class="hljs-string">"3000:3000"</span>            <span class="hljs-comment"># HTTP</span>
      - <span class="hljs-string">"9229:9229"</span>            <span class="hljs-comment"># Node.js inspector (debugger)</span>
    command: node --inspect=<span class="hljs-number">0.0</span><span class="hljs-number">.0</span><span class="hljs-number">.0</span>:<span class="hljs-number">9229</span> dist/index.js
    environment:
      - NODE_ENV=development</code></span></pre>


<p class="wp-block-paragraph">Port <code>9229</code> is the standard Node.js V8 inspector port. Exposing it from the container is all that is needed to attach a remote debugger.</p>



<h2 class="wp-block-heading">Enabling Debugging in WebStorm</h2>



<p class="wp-block-paragraph">To attach WebStorm to a running container:</p>



<ol class="wp-block-list">
  <li>Go to <strong>Run → Edit Configurations</strong> and add a new <strong>Node.js Remote Debug</strong> configuration.</li>
  <li>Set <strong>Host</strong> to <code>localhost</code> and <strong>Port</strong> to <code>9229</code>.</li>
  <li>In the <strong>Path mappings</strong> section, map your local <code>src/</code> directory to <code>/app/src</code> inside the container.</li>
  <li>Start the container with <code>docker compose up</code>, then click the debug button in WebStorm.</li>
</ol>



<h2 class="wp-block-heading">Enabling Debugging in Visual Studio Code</h2>



<p class="wp-block-paragraph">Add the following configuration to your <code>.vscode/launch.json</code>:</p>


<pre class="wp-block-code"><span><code class="hljs language-json">{
  <span class="hljs-attr">"version"</span>: <span class="hljs-string">"0.2.0"</span>,
  <span class="hljs-attr">"configurations"</span>: &#91;
    {
      <span class="hljs-attr">"type"</span>: <span class="hljs-string">"node"</span>,
      <span class="hljs-attr">"request"</span>: <span class="hljs-string">"attach"</span>,
      <span class="hljs-attr">"name"</span>: <span class="hljs-string">"Attach to Docker"</span>,
      <span class="hljs-attr">"address"</span>: <span class="hljs-string">"localhost"</span>,
      <span class="hljs-attr">"port"</span>: <span class="hljs-number">9229</span>,
      <span class="hljs-attr">"localRoot"</span>: <span class="hljs-string">"${workspaceFolder}/src"</span>,
      <span class="hljs-attr">"remoteRoot"</span>: <span class="hljs-string">"/app/src"</span>,
      <span class="hljs-attr">"sourceMaps"</span>: <span class="hljs-literal">true</span>,
      <span class="hljs-attr">"skipFiles"</span>: &#91;<span class="hljs-string">"&lt;node_internals&gt;/**"</span>]
    }
  ]
}</code></span></pre>


<p class="wp-block-paragraph">With the container running, press <strong>F5</strong> in VSCode to attach. Breakpoints set in your <code>.ts</code> source files will be hit correctly because source maps are enabled.</p>



<h2 class="wp-block-heading">Useful Boilerplate</h2>



<p class="wp-block-paragraph">If you want a ready-made starting point, the npm package <a href="https://www.npmjs.com/package/boilerplate-typescript-rest-docker" rel="noopener noreferrer" target="_blank">boilerplate-typescript-rest-docker</a> (source: npmjs.com) provides a pre-configured project scaffold covering TypeScript compilation, Docker setup, and debug configuration for both WebStorm and VSCode. Review its README for version-specific instructions before adopting it in a production project.</p>



<h2 class="wp-block-heading">Key Takeaways</h2>



<ul class="wp-block-list">
  <li>Use a multi-stage Dockerfile to separate build-time and runtime dependencies.</li>
  <li>Enable <code>sourceMap: true</code> in <code>tsconfig.json</code> so debuggers can map compiled JS back to TypeScript.</li>
  <li>Expose port <code>9229</code> and start Node with <code>--inspect=0.0.0.0:9229</code> for remote debugging.</li>
  <li>Configure path mappings in your IDE to point from local source files to the container filesystem.</li>
  <li>Docker Compose makes it easy to manage the development container lifecycle alongside other services such as databases or caches.</li>
</ul>
]]></content:encoded>
					
					<wfw:commentRss>https://www.bestdevops.com/how-to-use-typescript-docker-building-a-rest-service/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
