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.
-
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
- Clone the repository
git clone https://github.com/aysegules/PrismaComprehensiveTutorial.git- Install dependencies
npm install- 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 32This command will give you a secret key that generated randomly.
- 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- Start the development server
npm run devThe 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.