Skip to content

Latest commit

 

History

13 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prisma Comprehensive Tutorial

Node.js Express JWT Prisma PostgreSQL Zod Bcrypt dotenv

Introduction

This is a backend project which was built using Express framework and PostgreSQL database. With the use of Prisma ORM secure database management has provided. User, Post, and Product models were created in a different schema than public. User operations like register, login, and logout have been created in the controller file. Post operations have been created in its own controller file, as well. Aggregate functions such as count, sum, and avg were implemented in the product controller file to demonstrate how it is done.


Tech Stack

  • Node.js – JavaScript runtime for server-side development

  • Express.js – Fast, minimalist web framework for Node.js

  • JWT (JSON Web Tokens) – Secure authentication and authorization

  • Prisma – Next-generation ORM for database management

  • PostgreSQL – Powerful, open-source relational database

  • Zod – TypeScript-first schema validation library

  • bcryptjs – Password hashing for secure user authentication

  • dotenv – Environment variable management


Installation

  1. Clone the repository
git clone https://github.com/aysegules/PrismaComprehensiveTutorial.git
  1. Install dependencies
npm install
  1. Set up environment variables

Create a .env file in the root directory:

DATABASE_URL="postgresql://username:password@localhost:5432/DB_name?schema=public"
NODE_ENV="development/production"
PORT=5001
VERSION="/api/v1"
JWT_SECRET = "your-super-secret-jwt-key"
JWT_EXPIRES_IN="7d"
SEED_CREATOR_ID="uuid-for-seed.movies.js-file"

For the JWT secret variable you can run following command in terminal in your VS Code editor:

openssl rand -base64 32

This command will give you a secret key that generated randomly.

  1. Set up the database
# Run Prisma migrations
npx prisma migrate dev --name init

#Generate Prisma client
npx prisma generate

# (Optional) Seed the database with sample data
npm run seed:users
  1. Start the development server
npm run dev

The API will be available at: http://localhost:5001/api/v1


You can test your APIs with platforms like Postman, Requestly or another one which you prefer.

About

This is a backend project which was built using Express framework and PostgreSQL database. With the use of Prisma ORM secure database management has provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages