A boilerplate for building a backend project using Express, Prisma, and PostgreSQL. This boilerplate includes user registration and login functionality, along with essential middleware for handling HTTP exceptions, authorization, and schema validation.
- User Registration: Endpoint for user registration with name, gender, country, dateofbirth email and password.
- User Login: Endpoint for user login with email and password.
- HTTP Exception Handling: Middleware for handling HTTP exceptions and providing consistent error responses.
- Authorization Middleware: Middleware for user authentication and authorization.
- Schema Validation Middleware: Middleware for validating request payloads against predefined schemas.
- Node.js: Server-side JavaScript runtime.
- Express.js: Web application framework for Node.js.
- Prisma: Database toolkit for interfacing with the database.
- [Database System]: PostgreSQL for data storage.
- [Authentication Library]: jsonwebtoken for user authentication.
- [Other Libraries/Tools]: zod , bcrypt,dotenv etc...
Make sure you have the following installed on your system:
- Node.js (v20.9.0 or later)
- PostgreSQL (v16 or later)
-
Clone the Repository:
git clone https://github.com/honeyman22/backend-boilerplate.git
-
Install Dependencies:
cd boilerplate npm install
-
Set up the database:
- Create a PostgreSQL database.
- Update the database connection details in the .env file.
-
Run migrations:
npx prisma migrate dev
-
Start the Server:
bash npm start
Endpoint: POST /api/auth/register
Request Body :
{
"email": "user@example.com",
"name": "User",
"gender": "female",
"country": "Nepal",
"dateofbirth":"2012-2-12",
"password": "password123"
}
Endpoint: POST /api/auth/login
Request Body :
{
"email": "user@example.com",
"password": "password123"
}