Skip to content
/ bun-api-starter Public template

Bun (πŸ”) ElysiaJS / MongoDB API Starter

Notifications You must be signed in to change notification settings

cham11ng/bun-api-starter

Repository files navigation

bun-api-starter

Bun (πŸ”) API Starter CI

A robust Bun-based API starter built using ElysiaJS framework, and MongoDB as database. ElysiaJS, a type-safe and fast framework. MongoDB, a powerful NoSQL database. This starter offers a solid foundation for your API development, allowing you to focus on your unique business logic.

Getting Started

To install bun and starter packages.

curl -fsSL https://bun.sh/install | bash

bun install

Development

To start the development server run:

$ bun run dev
Environment: development
Bun (πŸ”) API Starter is running at localhost:8000
Info: MongoDB connection successful: starter

Open http://localhost:8000/docs with your browser to see the result.

cURL

curl --request POST \
  --url http://localhost:8000/login \
  --header 'Content-Type: application/json' \
  --data '{
  "email": "mail@example.com",
  "password": "secret@123"
}'

Docker

# development
$ docker compose up -d dev
[+] Running 2/3
 β ‹ Network bun-api-starter_default  Created           1.0s
 βœ” Container starter-mongodb        Started           0.5s
 βœ” Container starter-dev            Started           0.9s

# check logs
$ docker compose logs -f
# production
docker build --target production -t bun-api-starter-prod .
docker run -d --rm --env-file .env.docker \
  -p 8080:8000 \
  -t bun-api-starter-prod:latest

MongoDB Compass

# connect URI for root user.
mongodb://rootuser:root%40123@localhost:27017/starter?authSource=admin

Troubleshooting

# on default export error
const app = new Elysia();
export default app;

# double bun server initiated.
$ Bun (πŸ”) API Starter is running at localhost:8000
Started server http://localhost:3000

# do this
export const app = new Elysia();
// exception not captured onError.
function controller(context: Context) {}

// do this
const controller = (context: Context) => {}

Happy Coding

@cham11ng