Checklist production-grade untuk ElysiaJS: environment variables dengan Bun.env, structured logging, error handling global dengan onError dan notFound, health check endpoint, dan CI/CD pipeline dengan GitHub Actions.

Setelah di episode 19 kita memahami deployment, pada episode ini kita akan menutup series dengan production checklist — daftar lengkap yang harus dipenuhi sebelum aplikasi ElysiaJS di-deploy ke production.
const port = Number(Bun.env.PORT) || 3000
const jwtSecret = Bun.env.JWT_SECRET
const databaseUrl = Bun.env.DATABASE_URLBuat file .env untuk local development:
PORT=3000
JWT_SECRET=your-secret-key-here
DATABASE_URL=file:local.db
NODE_ENV=developmentJangan pernah hardcode secrets di source code. Gunakan secret manager dari platform deployment:
wrangler secret put.console.log tidak punya structured data — sulit difilter dan dianalisis di production. Gunakan structured logging:
function log(level: string, message: string, meta?: Record<string, any>) {
console.log(JSON.stringify({
timestamp: new Date().toISOString(),
level,
message,
...meta,
}))
}
// Penggunaan
log('info', 'User created', { userId: 123, email: 'john@example.com' })
log('error', 'Database error', { error: 'Connection refused', query: 'SELECT...' })Untuk production, gunakan library logging seperti pino:
bun add pinoimport pino from 'pino'
const logger = pino({
level: Bun.env.LOG_LEVEL || 'info',
})
app.onBeforeHandle(({ request }) => {
logger.info({ method: request.method, url: request.url }, 'Incoming request')
})app.onError(({ code, error, set }) => {
logger.error({ code, error: error.message }, 'Unhandled error')
switch (code) {
case 'VALIDATION':
set.status = 422
return { error: 'Validation failed', details: error.message }
case 'NOT_FOUND':
set.status = 404
return { error: 'Resource not found' }
default:
set.status = 500
return { error: 'Internal server error' }
}
})app.notFound(({ set }) => {
set.status = 404
return { error: 'Route not found' }
})app.get('/health', async ({ db }) => {
try {
await db.execute('SELECT 1')
return {
status: 'ok',
timestamp: Date.now(),
uptime: process.uptime(),
}
} catch (error) {
return { status: 'error', message: 'Database unreachable' }
}
})Health check penting untuk load balancer dan monitoring system.
name: Deploy
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v1
with:
bun-version: latest
- run: bun install --frozen-lockfile
- run: bun run lint
- run: bun test
- run: bun run build
- name: Deploy
run: # deployment commandPipeline ideal: lint → test → build → deploy. Setiap step harus lolos sebelum step berikutnya dijalankan.
Note
Production readiness bukan sekadar kode yang berfungsi. Logging, error handling, health check, dan CI/CD adalah fondasi yang memastikan aplikasi bisa diandalkan dan dipelihara dalam jangka panjang.
Episode 20 adalah episode terakhir dari series Belajar ElysiaJS. Kalian telah menempuh perjalanan lengkap dari pre-requisites hingga production readiness.
Inti yang harus dibawa pulang:
Bun.env untuk development, secret manager untuk production.app.onError() dan app.notFound() untuk error handling global.Selamat! Kalian telah menyelesaikan series Belajar ElysiaJS. Dari episode 0 hingga 20, kalian telah menguasai semua aspek penting untuk membangun API backend performa tinggi dengan ElysiaJS. Teruslah berlatih, bangun proyek nyata, dan jangan ragu untuk menjelajahi ekosistem plugin yang terus berkembang. Semangat!