This is a template for a NestJS project that leverages Docker / Github Codespaces for a dev environment.
The .devcontainer directory specifies the Codespaces configuration. This makes jumping into the codebase effortless. You don't even need to clone to your local machine.
As for Docker, the dockerfile is a pretty typical two stage build process for the app itself. The compose file wires up local dependencies (in this template that is DynamoDB, but you can add or remove as needed) and starts the app. The app service in the compose file mounts the root directory as a volume and overrides the command for the dockerfile. This is necessary to facilitate hot reloading even when the app is running inside of a docker container.
All of this is done to facilitate a positive developer experience. The entire development environment is extremely portable. All dependencies are entirely self contained.
To try this out in a new codespace:
- Scroll to the top of this page and click the "Code" button.
- Click the "Codespaces" tab
- Click the "New codespace" button
To start the app:
- Copy the .env.example file to .env (it contains no secrets, but I wanted to follow the best practice of not committing .env) by running
cp .env.example .env
- Run
docker-compose up
- Open command pallet (
CMD+SHIFT+P
), typeports
and hitReturn
to open the "Ports" view - Find the service running on port
3000
, right click and select "Open in Browser". This will take you to the Swagger docs of your running app via the Github Codespace proxy.
As I mentioned, this setup enables Hot Reloading. You can try this by editing the title of the API docs and then refreshing the docs tab.
Finally, because the app is running in a Docker container, you'll need to run your npm scripts indirectly. For example to run tests, run docker exec -it npm run test
. This opens up an interactive terminal with the container and then executes the npm run test
command.
A progressive Node.js framework for building efficient and scalable server-side applications.
Nest framework TypeScript starter repository.
$ npm install
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please read more here.
- Author - Kamil Myśliwiec
- Website - https://nestjs.com
- Twitter - @nestframework
Nest is MIT licensed.