Creating a Dev Container for TypeScript and VS Code — Part 2
Full-time Node.js dev container for less installation effort and more consistency.
--
Building on what we created in part 1, in this article we’ll cover:
- Initializing the Node.js project with npm
- “Hello, world!” console app in TypeScript
- “Hello, world!” web app in TypeScript
- Being specific about versioning
- Keeping dependencies up to date
Introduction
At the end of part 1, we have a dev container with Node.js and npm installed. We also have a suitable set of VS Code extensions for TypeScript development.
In part 2 we will complete the creation of the dev container by initializing the npm package and by installing the TypeScript compiler. We will also investigate a simple way to run a console application and a web site. We will conclude the article with some thoughts about managing dependencies.
The complete source code for this article is available on github.
Italics: As in the previous part, all is designed to run on Linux, MacOS and Windows without code changes. However, I will use italics to describe differences that are operating system specific where necessary.
Pre-Requisites
For this article you need the following prerequisites:
- VS Code
- VS Code extension “Remote Development”
- Git CLI (https://git-scm.com/downloads)
Linux only: You also need docker engine for Linux.
MacOS only: You also need Docker Desktop for MacOS.
Windows only: You also need
- WSL2 (Windows Subsystem for Windows 2)
- A Linux distribution (“distro”) such as Ubuntu 20.04 LTS
- Docker Desktop for Windows (install this one last)
Initializing the NPM Package
By convention when you start a Node.js code base, you initialize the containing directory with the following command: