Skip to content

Project for test and practice node js with express js basics

Notifications You must be signed in to change notification settings

Softx0/expressjs-template-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ExpressJS pet project

  • This is a pet project to verify some knowledge, practice expressJS, with Prisma as ORM to make migrations, joi for validations, versioning for controllers, swagger as a doumentation and cors for validation

Setup project

To setup the project

  1. Clone the repo
  2. Create at root the .env file

Example content:

DATABASE_URL="postgresql://YOUR_USERNAME:YOUR_PASSWORD@localhost:YOUR_PORT/YOUR_DATABASE?schema=public"
PORT=YOUR_APPLICATION_PORT
NODE_ENV=development
FRONTEND_URL=http://localhost:3001
JWT_SECRET=123456789012345678901234567890
JWT_EXPIRES_IN=30d
  1. Install the dependencies

Command: yarn install or yarn

  1. Then you can init prisma config & execute yout migrations from prisma to postgreSQL

Command: yarn prisma init

Command: yarn prisma migrate dev or npx prisma migrate deploy

4.0.1 Run the command to generated the prisma client

Command: npx prisma generate

4.1 If you want the Prisma Studio

Command: yarn prisma studio

  1. If always run success, then you can run run API

Command: yarn run dev

Database simple schema

Table Task

Fields

  • id String @id @default(uuid())
  • title String
  • description String?
  • status String @default("pending")
  • createdAt DateTime @default(now())
  • updatedAt DateTime @updatedAt

Endpoints

Create Task

curl -X POST http://localhost:3000/api/tasks \
-H "Content-Type: application/json" \
-d '{"title": "My first task", "description": "This is a test task", "status": "pending"}'

Get Tasks

curl http://localhost:3000/api/tasks

Get Tasks with filtering

curl "http://localhost:3000/api/tasks?page=1&limit=5&status=pending"

Get Task by id

curl http://localhost:3000/api/tasks/{task-id}

Edit Task by id

curl -X PUT http://localhost:3000/api/tasks/{task-id} \
-H "Content-Type: application/json" \
-d '{"title": "Updated task", "status": "completed"}'

Delete Task by id

curl -X DELETE http://localhost:3000/api/tasks/{task-id}

About

Project for test and practice node js with express js basics

Resources

Stars

Watchers

Forks