---
title: "How To Set Up TypeORM DataSource in Your NestJS Project"
url: https://daily.dev/posts/how-to-set-up-typeorm-datasource-in-your-nestjs-project-qqnjgksm2
source_url: https://www.freecodecamp.org/news/how-to-setup-typeorm-datasource-nestjs-app/
type: article
source: "freeCodeCamp"
published: 2024-04-25T13:32:32.412Z
updated: 2024-05-09T09:23:16.455Z
tags: ["javascript", "database", "nodejs", "typescript", "nestjs"]
reading_time: 10
upvotes: 87
comments: 2
language: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# How To Set Up TypeORM DataSource in Your NestJS Project

**[freeCodeCamp](https://daily.dev/sources/freecodecamp)** · 10 min read · 87 upvotes · 2 comments

## Summary

Learn how to set up TypeORM DataSource in your NestJS project. TypeORM is an ORM tool for Node.js and TypeScript applications, while NestJS is a Node.js framework. The tutorial covers the prerequisites, project setup, and setting up the TypeORM DataSource for data persistency. It also includes extending the DataSource repository for custom methods.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://www.freecodecamp.org/news/how-to-setup-typeorm-datasource-nestjs-app/>

## Community discussion

Top comments from developers on daily.dev.

**@virumabharathi** · 1 upvotes

> Hi , First of all its  Great but the thing I cant able to create a DB migration in the cli, ```npm run migration:generate --d migrations/newMigrations``` when i run this its asking for the dataSource.
>
> P.S - I'm new to Nest...

**@markojr** · 0 upvotes

> You could do so much more with so much less code
>
> why do you create your own `TypeOrmModule` which exports your Datasource .. you already have installed `@nestjs/typeorm`
>
> you can use the official Module provided by the package
>
>
> use also the `@nestJs/config`  module to make the config of your DB-Connection configureable
>
> instead of chaining multiple `nest g` commands you could just run `nest g resource`
>
>
> in your user-service you can directly inject a repository
>
> ```ts
> // BAD
> constructor(private dataSource: DataSource) {
>     // get users table repository to interact with the database
>    ...

## Similar posts on daily.dev

- [Don’t just attend KubeCon \+ CloudNativeCon, Merge Forward your experience\!](https://daily.dev/posts/don-t-just-attend-kubecon-cloudnativecon-merge-forward-your-experience--l0rpp73x8) · CNCF · 0 upvotes · 0 comments
- [Announcing H2 2026 KCDs](https://daily.dev/posts/announcing-h2-2026-kcds-m96goajm1) · CNCF · 1 upvotes · 0 comments
- [Two months of Open Community Groups](https://daily.dev/posts/two-months-of-open-community-groups-asf52zhbs) · CNCF · 0 upvotes · 0 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#database](https://daily.dev/tags/database), [#nodejs](https://daily.dev/tags/nodejs), [#typescript](https://daily.dev/tags/typescript), [#nestjs](https://daily.dev/tags/nestjs)

[View this post on daily.dev](https://daily.dev/posts/how-to-set-up-typeorm-datasource-in-your-nestjs-project-qqnjgksm2)
