This project is a minimal task management application built with React and TypeScript on the frontend, Node.js on the backend, and PostgreSQL as the database. It includes user registration, login (with JWT-based authentication and bcrypt password hashing), and task CRUD operations.
- PostgreSQL installed on your system. You can find official downloads here.
- A PostgreSQL client (e.g.,
psqlor pgAdmin) to run SQL scripts.
-
Create the Database:
Create a new PostgreSQL database (name used in this project is
task_app, if you are changing this, you must change all references to this)CREATE DATABASE task_app;
-
Run Migrations:
Execute the following SQL commands to create the required tables:
-- Create the users table CREATE TABLE users ( id SERIAL PRIMARY KEY, username VARCHAR(255) UNIQUE NOT NULL, password VARCHAR(255) NOT NULL ); -- Create the tasks table CREATE TABLE tasks ( id SERIAL PRIMARY KEY, title VARCHAR(255) NOT NULL, description TEXT, "complete" BOOLEAN DEFAULT false, "userid" INTEGER REFERENCES users(id) );
-
Environment Variables:
Edit the
.envfile in the server directory. Placeholders/defaults are used, but you should use your own values.PORT=5000 BCRYPT_SALT_ROUNDS=10 JWT_SECRET=SECRET_KEY DATABASE_URL=postgres://username:password@localhost:5432/task_appAt minimum, you should replace
SECRET_KEY,username, andpasswordwith your own values. You can generate a JWT key here.usernameandpasswordshould be your PostgreSQL username and password.5432is the default port for PostgreSQL, but if you have a different port you should change it to your port.
- Node.js
- npm
-
Navigate to the
server/directory. -
Install dependencies:
npm install
-
Run the backend server (development mode):
npm run dev
-
The server should start on the port specified in your
.envfile (default is5000).
- Node.js
- npm
-
Navigate to the
client/directory. -
Edit the
.envfile in the frontend directory. It only has one value:REACT_APP_API_URL=http://localhost:5000Adjust the URL if your backend is hosted elsewhere.
-
Install dependencies:
npm install
-
Run the frontend application:
npm start
-
The React app will launch in your default browser (typically at
http://localhost:3000).
- Manual API Testing:
- You can use backend testing tools such as Postman to test the backend.
- Registration:
POST /auth/register - Login:
POST /auth/login(retrieve a JWT) - Tasks Endpoints: Use the JWT in the
authorizationheader (e.g.,Bearer <token>) for:GET /tasksPOST /tasksPUT /tasks/:idDELETE /tasks/:id