1001Ferramentas
🟪Dev

TypeORM Init Generator

Generate a starter TypeORM data-source.ts with a ready PostgreSQL connection, in TypeScript. Copy the file and start using entities and migrations.



  

A TypeORM data source wired for Postgres

TypeORM makes you build a DataSource before a single entity does anything useful. That is where host, port, the synchronize flag and the entity and migration globs live, and getting any of them wrong produces connection errors that look like database trouble but are pure configuration. This page gives you a starter data-source.ts for Postgres that reads everything from environment variables.

The output is fixed and there is no form: one function returns the same text every time, already rendered when the page opens. Every field has a fallback, so DB_HOST becomes localhost, DB_PORT becomes 5432 and DB_NAME becomes app, and you can run locally with no .env at all. synchronize is false on purpose; with true, TypeORM rewrites your schema on every boot, which is fine for a sketch and dangerous in production.

Check three things after pasting. Your tsconfig needs experimentalDecorators and emitDecoratorMetadata or the entities will not compile. The globs point at src/entities/*.ts, so once tsc emits to dist you have to point them at dist/entities/*.js. And the data source never connects on its own: call AppDataSource.initialize() during bootstrap and handle the promise it returns. Generation happens entirely in your browser.

Frequently asked questions

Can it generate a MySQL or SQLite version?
Not from the page: type is fixed as postgres. It is a one-line change plus the matching driver in package.json.
Why are my entities not found in production?
Because the globs still point at .ts files. After the TypeScript build, target dist/entities/*.js or import the entity classes straight into the entities array.
Do I really need import 'reflect-metadata'?
Yes, and it has to run before any entity is loaded. That import is what lets TypeORM read the decorators.

Related Tools