Skip to content

πŸš€ hono-starter - A Typescript API with Node + Hono + Drizzle + MySQL + BullMQ

License

Notifications You must be signed in to change notification settings

brian-kiplagat/hono-starter

Β 
Β 

Repository files navigation

Hono Starter

A Hono starter boilerplate for TypeScript with minimal dependencies and a clean architecture. All dependencies are initiated at the start of the application and passed to the controllers and services. A swagger API doc is attached in the static folder: openapi.yaml.

API Doc powered by Swagger UI

Screenshot 2024-09-28 at 12 48 21β€―AM

Database browser powered by Drizzle Studio

Screenshot 2024-09-28 at 12 46 26β€―AM

Stack

  • Authentication: JWT
  • Validation: Zod
  • Worker: BullMQ
  • Logging: Pino
  • ORM: Drizzle
  • Queue: Redis
  • DB: MySQL
  • Runtime: NodeJS
  • Framework: Hono
  • Formatter: Biome
  • API Doc: Swagger
  • Language: TypeScript
  • Package Manager: PNPM

Install dependencies

pnpm install
pnpm install -g typescript
pnpm install -g pino-pretty

Spin docker for developement

Create a new file .env in the root folder and copy contents from the .env.template file and run this command. You must have docker installed on your computer. If not, skip to Install Docker Desktop then return here once done. Ideally for local developemnt you only need to run this step once to install require dependencies like mysql. Subsequently you can just turn the container on or off at will in Docker desktop

docker compose up -d

Generate

pnpm run db:generate

Migrate

pnpm run db:migrate

Run the app

pnpm run dev
open http://localhost:3000/doc

API Doc

The OpenAPI YAML doc is in the static folder.

If you need the JSON file, it can be generated with the help of yq.

https://github.com/mikefarah/yq

yq eval -o=json static/openapi.yaml > static/openapi.json

And the JSON doc will be generated.

Drizzle Studio For Database Browsing

pnpm drizzle-kit studio
open https://local.drizzle.studio/

Docker for local development

To install Docker on Windows, you'll need to install Docker Desktop and WSL 2 (Windows Subsystem for Linux). Below are the step-by-step instructions:


1. Enable WSL 2 and Install a Linux Distribution

WSL 2 is required for Docker to run on Windows efficiently.

Step 1: Enable WSL

  1. Open PowerShell as Administrator and run the following command to enable WSL:

    wsl --install

    This will install the default Linux distribution (Ubuntu) and enable WSL 2.

  2. Restart your computer after installation.


2. Install Docker Desktop

Step: Download Docker Desktop

Step: Install Docker Desktop

  1. Run the Docker Desktop Installer.exe file.

  2. In the installation settings:

    • Ensure "Use WSL 2 instead of Hyper-V" is checked.
    • Click Install and wait for the process to complete.
  3. Once the installation is done, click Close and restart.


3. Configure Docker to Use WSL 2

  1. Open Docker Desktop.
  2. Go to Settings > General.
  3. Check "Use the WSL 2 based engine".
  4. Click Apply & Restart.

4. Verify Installation

  1. Open PowerShell or Command Prompt and run:

    docker --version

    This should return the installed Docker version.

  2. Run the hello-world container to test:

    docker run hello-world

    If everything is set up correctly, you will see a message confirming that Docker is working.


Optional: Confirm MySQL Works

Once the migration is complete, and you've run:

pnpm run db:generate
pnpm run db:migrate

Confirm that MySQL inside the container works on the WSL Ubuntu command line using the credentials from your .env file.

To connect to MySQL using the .env credentials you provided (DB_USER=user, DB_PASSWORD=password), follow these steps:


1. Open Ubuntu in WSL

Run the following in PowerShell or Command Prompt:

wsl

2. List Running Docker Containers

Inside Ubuntu, check if MySQL is running in Docker:

docker ps

Look for the CONTAINER ID of the MySQL container.


3. Access MySQL Inside the Container

Now, use the CONTAINER ID to execute MySQL:

sudo docker exec -it <CONTAINER_ID> mysql -u user -p

Replace <CONTAINER_ID> with the actual ID from docker ps. When prompted, enter the password (password from .env).


4. Verify Database Access

Once inside MySQL, check if the database exists:

SHOW DATABASES;

To use a specific database:

USE your_database_name;
SHOW TABLES;

5. Exit MySQL

To exit the MySQL shell, type:

EXIT;

image


Troubleshooting

  • If the container is not running, start it:
    docker start <CONTAINER_ID>
  • If you don’t see the container in docker ps, check all containers:
    docker ps -a
  • If MySQL is not installed in Docker, check the logs:
    docker logs <CONTAINER_ID>

This ensures that MySQL is running correctly within the Docker container on WSL! πŸš€

Conclusion

Now you have Docker installed with WSL 2 support. You can run Linux-based Docker containers efficiently on Windows! πŸš€

About

πŸš€ hono-starter - A Typescript API with Node + Hono + Drizzle + MySQL + BullMQ

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 98.6%
  • Dockerfile 1.3%
  • Shell 0.1%