89 lines
2.1 KiB
Markdown
89 lines
2.1 KiB
Markdown
# Dyolink — Backend (NestJS)
|
|
|
|
## Prerequisites
|
|
|
|
- **Node.js 20+** and **npm**
|
|
- **PostgreSQL** reachable from your machine (local or remote)
|
|
|
|
## First-time setup
|
|
|
|
1. **Clone the monorepo** and go to the backend app:
|
|
|
|
```bash
|
|
git clone <repository-url> dyolink
|
|
cd dyolink/backend
|
|
```
|
|
|
|
2. **Install dependencies**
|
|
|
|
```bash
|
|
npm install
|
|
```
|
|
|
|
3. **Environment**
|
|
|
|
Copy `.env.example` to `.env` and set at least:
|
|
|
|
- `DATABASE_URL` — PostgreSQL connection string for your dev database
|
|
- `JWT_SECRET` — strong secret for signing tokens
|
|
Do not commit `.env`.
|
|
|
|
4. **Database URL for local dev**
|
|
|
|
Point `DATABASE_URL` at a database you created in Postgres (create an empty DB first if needed).
|
|
|
|
5. **Generate Prisma Client**
|
|
|
|
```bash
|
|
npm run prisma:generate
|
|
```
|
|
|
|
6. **Apply migrations** (creates/updates tables to match `prisma/schema.prisma`)
|
|
|
|
```bash
|
|
npm run prisma:migrate
|
|
```
|
|
|
|
This runs `prisma migrate dev`. Use it during development when the schema changes.
|
|
|
|
7. **Seed** (optional — sample data / bootstrap)
|
|
|
|
```bash
|
|
npm run prisma:seed
|
|
```
|
|
|
|
## Run (development)
|
|
|
|
```bash
|
|
npm run start:dev
|
|
```
|
|
|
|
API listens on **`http://localhost:3000`** by default (`PORT` in `.env`).
|
|
|
|
If the frontend runs on another origin (e.g. `http://localhost:3001`), set `CORS_ORIGIN` in `.env` to that URL.
|
|
|
|
## After pulling latest `main`
|
|
|
|
```bash
|
|
git pull
|
|
npm install
|
|
npm run prisma:generate
|
|
npm run prisma:migrate
|
|
```
|
|
|
|
If teammates added migrations, step 4 applies them. Resolve migration conflicts locally before pushing.
|
|
|
|
## Useful commands
|
|
|
|
| Command | Purpose |
|
|
|--------|---------|
|
|
| `npm run prisma:generate` | Regenerate client after `schema.prisma` changes |
|
|
| `npm run prisma:migrate` | Dev migrations (`migrate dev`) |
|
|
| `npm run prisma:deploy` | Production-style apply (`migrate deploy`) — e.g. CI/containers |
|
|
| `npm run build` | Compile Nest app |
|
|
| `npm run start:prod` | Run compiled app (`node dist/main`) |
|
|
|
|
## Docker
|
|
|
|
Image build is defined in **`Dockerfile`** at this folder. For full-stack deployment and CI, see the **repository root `README.md`**.
|