This is a personal practice project for experimenting with Prisma, Express.js, and PostgreSQL.
git clone <repository-url>
cd expressjs-prisma-postgres-demo
npm install
- Open psql shell and connect postgres database on your local machine
psql -h localhost -p 5432 -U postgres postgres
- Create database using psql
CREATE DATABASE your-db-name;
- Create a new user with a password on you postgresql server and give it rule as superuser
CREATE USER your-db-user WITH PASSWORD your-password SUPERUSER;
- Exit the
psql
shell
\q
-
In src/config/.env, provide the necessary database credentials:
DATABASE_URL=postgresql://<username>:<password>@localhost:5432/<DB> DATABASE_DEV=db_name DATABASE_PROD=db_name DATABASE_TEST=db_name DATABASE_USERNAME=user_name DATABASE_PASSWORD=password
-
In `prisma/.env``, make sure the database URL matches your PostgreSQL database configuration:
# db_url like that 'postgresql://mo:test123@localhost:5432/prisma_demo' DATABASE_URL=db_url DATABASE_URL_TEST=db_url
npx prisma migrate dev
- Development Mode: Run npm run
start:dev
to start the server with nodemon for automatic reloading during development. - Production Mode: Run npm run
start:prod
to start the server in production mode.
- Run tests using Jest:
npm test
: Run tests in the testing environment.npm run test:coverage
: Run tests with code coverage report.
- Use your preferred API client (e.g., Postman, curl) to interact with the API.
- Alternatively, you can use the REST Client extension in Visual Studio Code to test the API directly from the provided
rest.http
file. Therest.http
file contains URLs to all endpoints, making it convenient to make requests and test your API.
The npm test command will not only start the server but also run Jest for testing purposes.
Enjoy the demo!