This repository contains a REST API built with Node.js and PostgreSQL, enabling CRUD operations (create, read, update, delete) on users using token-based authentication via JWT (Json Web Token).
- Clone the repository:
git clone https://github.com/solarluiso/api-rest-ts-postgresql
- Open the project in your code editor and run the following command in your terminal:
npm install
- Set up your environment variables by creating a
.env
file using the template provided. - With Docker Desktop running, execute:
docker compose up -d
- Start the server by running:
npm run dev
- NODE: Ensure Node.js is installed on your operating system.
- DOCKER: Required to run the MongoDB image in a container.
- GIT: Make sure Git is also installed.
- Initialize the project:
npm init -y
- Install the required packages:
npm install express jsonwebtoken bcrypt @prisma/client dotenv typescript
npm install --save-dev ts-node-dev @types/express @types/jsonwebtoken @types/bcrypt @types/node rimraf prisma
- Initialize TypeScript configuration:
npx tsc --init --outDir dist/ --rootDir src
- Update the TypeScript configuration file with excluded and included folders:
"exclude": ["node_modules","dist" ], "include": ["src"]
- Initialize Prisma:
npx prisma init
- Generate Prisma client:
npx prisma generate
- Add models in
schema.prisma
- Apply migrations:
npmx prisma migrate dev
- Start Docker Compose:
docker-compose up -d
- Add the following scripts to
package.json
:"dev": "tsnd --respawn --clear src/app.ts", "build": "rimraf ./dist && tsc", "start": "npm run build && node dist/app.js"
http://localhost:3000/auth/register http://localhost:3000/users http://localhost:3000/auth/login