An API for serve a backend to manage a simple blog.
- NodeJS (v16+)
- Typescript
- MongoDB
Built-in:
npm install
Create .env
file:
cp .env.example .env
💭 Don't forget to fill environments variables in .env file.
Start MongoDB using Docker-Compose:
docker-compose up -d
⚠️ Because this app use Prisma, the MongoDB must be set a replicaSet.See in docs: Prisma.
Generate schema:
npm run generate
model Post {
id String @id @default(auto()) @map("_id") @db.ObjectId
text String
user User @relation(fields: [userId], references: [id])
userId String @db.ObjectId
createdAt DateTime @default(now())
}
model User {
id String @id @default(auto()) @map("_id") @db.ObjectId
name String
nickname String
posts Post[]
}
This diagram will be generated:
This diagram will be created in prisma folder.
erDiagram
User {
Int id PK "autoincrement()"
String email
String name "nullable"
}
Post {
Int id PK "autoincrement()"
String title
String content "nullable"
Boolean published
Int authorId FK
}
Post }o--|| User : author
You can running using node scripts or makefile.
⚠️ Remember to set DATABASE URL and PORT in.env
file.
Running from source code:
npm run dev
or
npm run watch
Building application:
npm run build
Running from compiled:
npm run start
Building image
make build
Starting
make start
- Leo Yassuda