This is the backend for a full-stack Todo application built with Node.js, Express, Prisma ORM, PostgreSQL, and JWT authentication.
-
User Signup & Signin
Users can register and log in. JWT tokens are used for authentication. -
Todo Management
Authenticated users can create, view, and delete their own todos. -
REST API Endpoints
POST /signup— Register a new userPOST /signin— Authenticate and receive a JWTPOST /todos— Create a new todo (requires JWT)GET /todos— Get all todos for the authenticated user (requires JWT)DELETE /todo/:id— Delete a todo by ID (requires JWT)
-
CORS Enabled
Allows the React frontend (running on a different port) to communicate with the backend.
- Backend: Node.js, Express, Prisma ORM, PostgreSQL, JWT, CORS
- Node.js and npm
- PostgreSQL
-
Clone the repository and navigate to the backend folder:
cd Postgress -
Install dependencies:
npm install
-
Configure environment variables:
Create a.envfile in the root with:DATABASE_URL="postgresql://<username>:<password>@localhost:5432/<dbname>?schema=public" JWT_KEY=your_secret_key -
Run Prisma migrations:
npx prisma migrate dev --name init
-
Start the backend server:
node index.js
- Sign up with your name, username, and password.
- Sign in to receive a JWT token.
- Create, view, and delete todos while authenticated.
- The backend expects the JWT token in the
tokenheader for protected routes. - Make sure both backend and frontend servers are running.
- Adjust CORS settings in
index.jsif you deploy to production.