In just 3 simple steps, you can use Kool to start a new NestJS application running in a local Docker development environment.
Kool is a free, open source CLI tool that makes local development with Docker super easy. Kool CLI will level up your development workflow, and help you and your team improve the way you develop and deploy cloud native applications.
After installing NestJS, kool create automatically runs the kool preset nestjs command, which helps you set up the initial tech stack for your project using an interactive wizard.
$Preset nestjs is initializing!
? Which database service do you want to use [Use arrows to move, type to filter]
>MySQL 8.0
MySQL 5.7
PostgreSQL 13.0
none
? Which cache service do you want to use [Use arrows to move, type to filter]
>Redis 6.0
Memcached 1.6
none
? Which package manager did you choose during Nest setup [Use arrows to move, type to filter]
>npm
yarn
$Preset nestjs initialized!
Now, move into your new NestJS project:
$cd my-project
The kool preset command auto-generated the following configuration files and added them to your project, which you can easily modify and extend to suit your needs.
+docker-compose.yml
+kool.yml
Step 2 (Optional) – Add Environment Variables
You can skip this step if you did not add a database or cache service to your project via the wizard.
If you added a database and/or cache service, you'll need to add some local environment variables to match the services in your docker-compose.yml file (see below). For example, you'll need to change the hosts from localhost to the appropriate service container name, which are accessible from within Docker.
Create a .env file inside your project's root directory, and add the appropriate environment variables to this file (as provided below) based on the services used in your project.
Now, spin up your local environment for the first time using the setup script in your kool.yml file:
$kool run setup
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.3.1 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
audited 879 packages in 32.143s
78 packages are looking for funding
run `npm fund` for details
found 0 vulnerabilities
Creating network "my-project_kool_local" with the default driver
Creating volume "my-project_database" with default driver
Creating volume "my-project_cache" with default driver
Creating my-project_database_1 ... done
Creating my-project_app_1 ... done
Creating my-project_cache_1 ... done
That's it!
Once kool run setup finishes, you can access your new NestJS app at http://localhost:3000 and see the NestJS "Hello World!" welcome page.
Level Up Your Workflow
Now that you have your new NestJS app up and running, you can use the Kool CLI to start leveling up your development workflow.
Add Scripts to kool.yml
Think of kool.yml as a super easy-to-use task helper. Instead of writing custom shell scripts, you can add your own scripts to kool.yml (under the scripts key), and run them with kool run SCRIPT. You can add single line commands (kool run nest), or add a list of commands that will be executed in sequence (kool run setup). For example, add scripts to run database migrations, reset local environments, run static analysis tools, and so on. Think about how much easier it will be to onboard a teammate or new developer :)
scripts:mysql:kool exec -e MYSQL_PWD=$DB_PASSWORD database mysql -u $DB_USERNAME $DB_DATABASE# or psql for PostgreSQLnest:kool exec app nestnpm:kool exec app npm# or yarnnpx:kool exec app npxsetup:-kool docker kooldev/node:14 npm install# or yarn install-kool start
Run Commands
When you need to execute a command inside a running service container, use the kool exec command. Run the following to check the version of Node running in your app container.
$kool exec app node -v
v14.17.1
Connect to the Database
If you added a database service, start a new SQL client session inside your running database container by executing kool run mysql (MySQL) or kool run psql (PostgreSQL). This runs the mysql or psql script in your kool.yml.
Add Dependencies
As your project evolves, and you add more dependencies to package.json, use the kool restart command to restart your app container and load the new packages.
View container logs using the kool logs command. Run kool logs to see the logs for all running containers, or kool logs app to specify a service and only see the logs for the app container. Add the -f option after kool logs to follow the logs (i.e. kool logs -f app).
Share Your Work
When you need to quickly share local changes with your team, use the kool share command to share your local environment over the Internet via an HTTP tunnel. Specify your own subdomain using the --subdomain flag.
$kool share --port=3000
Thank you for using expose.
Local-URL: app:3000
Dashboard-URL: http://127.0.0.1:4040
Expose-URL: https://eeskzijcbe.kool.live
Remaining time: 00:59:59
Remaining time: 00:59:58
Remaining time: 00:59:57
Switch Projects
Kool supports any language or framework, so you can standardize the way you work across all your tech stacks. When it's time to stop working on your new NestJS app and switch to a different project, you can easily change local Docker environments by running kool stop on the NestJS project, moving into the other project directory, and running kool start.
$kool stop
$cd ~/my-other-project
$kool start
Pretty kool, right?
If you like what we're doing, show your support for this new open source project by starring us on GitHub!
From local development to the cloud: web apps development with containers made easy.
About kool
Kool is a CLI tool that brings the complexities of modern software development environments down to earth - making these environments lightweight, fast and reproducible. It reduces the complexity and learning curve of Docker containers for local environments, and offers a simplified interface for using Kubernetes to deploy staging and production environments to the cloud.
Kool gets your local development environment up and running easily and quickly, so you have more time to build a great application. When the time is right, you can then use Kool.dev Cloud to deploy and share your work with the world!
Kool is suitable for solo developers and teams of all sizes. It provides a hassle-free way to handle the Docker basics and immediately start using containers for development, while simultaneously guaranteeing no loss of control over more specialized Docker environments.