Encore is the TypeScript/Go backend framework that generates cloud infrastructure from your code. Define an API endpoint — Encore provisions databases, queues, cron jobs, and Pub/Sub automatically.
What Is Encore?
Encore analyzes your code and generates the infrastructure you need. No Terraform, no Kubernetes YAML, no infra setup. Write code, get infrastructure.
Quick Start
npm install encore.dev
Encore init my-app --lang=ts
Define an API
// backend/hello/hello.ts
import { api } from 'encore.dev/api'
export const get = api(
{ method: 'GET', path: '/hello/:name', expose: true },
async ({ name }: { name: string }) => {
return { message: `Hello, ${name}!` }
}
)
// That is it. Encore generates the HTTP server, routing, docs, and monitoring.
Database (Auto-Provisioned)
// backend/todo/db.ts
import { SQLDatabase } from 'encore.dev/storage/sqldb'
const db = new SQLDatabase('todo', {
migrations: './migrations',
})
// Encore automatically provisions PostgreSQL in dev, staging, and prod
export const create = api(
{ method: 'POST', path: '/todos', expose: true },
async (params: { title: string }) => {
const row = await db.queryRow`
INSERT INTO todos (title, done) VALUES (${params.title}, false)
RETURNING id, title, done
`
return row
}
)
export const list = api(
{ method: 'GET', path: '/todos', expose: true },
async () => {
const rows = await db.query`SELECT id, title, done FROM todos ORDER BY id`
return { todos: rows }
}
)
Pub/Sub (Auto-Provisioned)
import { Topic, Subscription } from 'encore.dev/pubsub'
// Define topic
export const OrderCreated = new Topic<{ orderId: string; amount: number }>('order-created')
// Publish
export const createOrder = api(
{ method: 'POST', path: '/orders', expose: true },
async (order: { items: string[] }) => {
const orderId = crypto.randomUUID()
await OrderCreated.publish({ orderId, amount: 99.99 })
return { orderId }
}
)
// Subscribe (runs automatically)
new Subscription(OrderCreated, 'process-payment', {
handler: async (event) => {
console.log(`Processing payment for order ${event.orderId}: $${event.amount}`)
await chargeStripe(event.orderId, event.amount)
},
})
Cron Jobs (Built-In)
import { CronJob } from 'encore.dev/cron'
new CronJob('daily-cleanup', {
title: 'Clean up expired sessions',
schedule: '0 2 * * *', // 2 AM daily
endpoint: cleanup,
})
export const cleanup = api({ expose: false }, async () => {
await db.exec`DELETE FROM sessions WHERE expires_at < NOW()`
return { cleaned: true }
})
What Encore Auto-Generates
- HTTP server and routing
- PostgreSQL databases and migrations
- Pub/Sub topics and subscriptions
- Cron job scheduling
- API documentation (OpenAPI)
- Distributed tracing
- Architecture diagrams
- Service-to-service auth
Deployment
git push encore # Deploy to Encore Cloud
# Or self-host on AWS/GCP
encore build docker my-app:v1
Need to auto-generate infrastructure for scraping? Scrapfly handles scraping infrastructure at scale. Email spinov001@gmail.com for custom setups.
Top comments (0)