Library | Description |
---|---|
Node.js | JavaScript runtime built on Chrome's V8 JavaScript engine |
Express | Minimal and flexible Node.js web application framework for creating APIs. |
TypeScript | A strongly typed programming language that builds on JavaScript, giving you better tooling at any scale. |
ESLint | Statically analyzes your code to quickly find problems. |
Jest | A delightful JavaScript testing framework with a focus on simplicity. |
Docker | Package software into standardized units for development, shipment and deployment |
Node-TypeScript-Express-Docker-Starter is a template repo for building a Node.js APIs with TypeScript, Express and Docker. This template contains a minimal ESLint configuration to enforce coding styles, and comes equipped with Jest for unit and integration testing. Additionally, this project's API routes are structured similarly to how components are organized in an Angular project. Controllers are grouped by the API resource they serve, and the associated unit (spec.ts) and integration (e2e.ts) files live in the same directory.
Install Docker Desktop, VS Code and Git. Click the green Use this template button to copy this repo to your GitHub account. Once you've copied the repo, clone it to your workspace (be sure to replace my URL with the URL to the repo you generated by clicking Use this template
):
git clone https://github.com/bobbyg603/node-typescript-express-docker-starter
Install the project's dependencies:
npm i
Run the unit and integration tests to ensure everything installed correctly:
npm test && npm run e2e
You can also run and debug tests from within the VS Code Testing Explorer by installing Jest Test Explorer.
This template requires Node.js version 19+. A .nvmrc
file has been included in this repo so that nvm can be used to quickly switch between major versions of Node.js.
Install nvm for POSIX or Windows and run the following command at the root of the repo to switch to Node.js 18:
nvm use
If you'd like to automatically build and restart the development sever when source files are changed you can can run the watch
command:
npm run watch
The development server can also be started without watching the local file system or attaching the debugger:
npm start
If you'd like to attach the VS Code Debugger to a Node.js instance running on your local machine use the Launch Program task.
The development server should begin listening for web requests. If you navigate to http://localhost:3000 in your browser you should see something that resembles the following:
The VS Code Debugger can also be attached to a Node.js instance running inside a Docker container via the Docker: Node.js Launch task.
If you'd like to watch your file system for changes and reload your application when changes are detected you can run the build:watch
command on the host machine:
npm run build:watch
If you believe that this example can be improved, please open an issue or submit a pull request!