1. EasyHost
  2. Guides
  3. Next.js
  4. TypeORM

Use TypeORM with Next.js and Postgres

Connect a Next.js app to a free EasyHost Postgres database using TypeORM, from install to deployment.

Last updated November 9, 2026

Create the database

npx ezhst db create main
npx ezhst db info --json
npx ezhst env set DATABASE_URL="postgresql://..."

The connection string uses a public host with TLS, so it works from your laptop too. Put it in your local .env for development.

Install TypeORM

npm i typeorm pg reflect-metadata

Create the client

lib/db.ts
import "reflect-metadata";
import { DataSource } from "typeorm";

export const db = new DataSource({
  type: "postgres",
  url: process.env.DATABASE_URL,
  entities: [],
});

await db.initialize();

Keep synchronize off in production, and run migrations from your machine against the connection string. Register your entities in the entities array.

If Next.js fails to bundle a database driver, list the package under serverExternalPackages in next.config.ts.

Query it from a route

app/api/users/route.ts
import { db } from "@/lib/db";
export const GET = async (request: Request) => {
  const rows = await db.query("select id, email from users limit 20");
  return Response.json(rows);
};

Run migrations

Run migrations from your machine, with DATABASE_URL set to the EasyHost connection string.

npx typeorm migration:run -d dist/data-source.js

Commit the migration files so every environment applies the same changes.

Deploy

npx ezhst deploy

Each database allows 20 concurrent connections, and Next.js shares them across requests. See the Next.js hub for every Next.js guide, or free Next.js hosting for what is included. See also the Postgres product page.

Frequently asked questions

Is Postgres free for my Next.js app?

Yes. Each EasyHost project can have one Postgres 16 database with no expiry date.

Can I use TypeORM locally against the same database?

Yes. The connection string works from outside EasyHost. A separate development database is safer once you have real data.

Start for free

Install the skill, choose Global or Local, then tell your agent to deploy. No credit card, no config files.

npx ezhst skill install