A full-stack todo application built with Node.js, Express.js, SQLite, and JWT authentication. This project demonstrates modern backend development practices with TypeScript.
- User Authentication: Secure registration and login with JWT tokens
- Password Security: Passwords are hashed using bcrypt
- Todo Management: Create, read, update, and delete todos
- User-specific Data: Each user can only access their own todos
- SQLite Database: Lightweight database with foreign key constraints
- TypeScript: Full type safety throughout the application
- Responsive UI: Clean and modern frontend interface
- Node.js - Runtime environment
- Express.js - Web application framework
- TypeScript - Type-safe JavaScript
- SQLite - Lightweight database
- better-sqlite3 - SQLite driver for Node.js
- JWT - JSON Web Tokens for authentication
- bcryptjs - Password hashing
- HTML5 - Markup language
- CSS3 - Styling
- Vanilla JavaScript - Client-side logic
- Font Awesome - Icons
- tsx - TypeScript execution engine
- ESLint - Code linting
- Prettier - Code formatting
- pnpm - Package manager
backend-learning/
├── src/
│ ├── db.ts # Database configuration and schema
│ ├── server.ts # Main server file
│ ├── middleware/
│ │ └── auth-middleware.ts # JWT authentication middleware
│ └── routes/
│ ├── auth-routes.ts # Authentication routes
│ └── todo-routes.ts # Todo CRUD routes
├── public/
│ ├── index.html # Frontend HTML
│ ├── styles.css # Custom styles
│ └── fanta.css # Additional styling
├── .env.example # Environment variables template
├── package.json # Project dependencies
├── tsconfig.json # TypeScript configuration
└── README.md # This file
- Node.js (v18 or higher)
- pnpm (or npm/yarn)
-
Clone the repository
git clone https://github.com/JimmFly/backend-learning.git cd backend-learning -
Install dependencies
pnpm install
-
Set up environment variables
cp .env.example .env
Edit
.envand add your JWT secret:JWT_SECRET=your-super-secret-jwt-key-here PORT=3000 -
Start the development server
pnpm dev
-
Access the application Open your browser and navigate to
http://localhost:3000
| Method | Endpoint | Description | Body |
|---|---|---|---|
| GET | /auth |
Get all users (development only) | - |
| POST | /auth/register |
Register a new user | {username, password} |
| POST | /auth/login |
Login user | {username, password} |
| DELETE | /auth/delete-account |
Delete user account | {username, password} |
| Method | Endpoint | Description | Body | Headers |
|---|---|---|---|---|
| GET | /todos |
Get all user's todos | - | Authorization: <token> |
| POST | /todos |
Create a new todo | {task} |
Authorization: <token> |
| PUT | /todos/:id |
Update a todo | {task?, completed?} |
Authorization: <token> |
| DELETE | /todos/:id |
Delete a todo | - | Authorization: <token> |
CREATE TABLE users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL UNIQUE,
password TEXT NOT NULL
);CREATE TABLE todos (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
task TEXT NOT NULL,
completed BOOLEAN NOT NULL DEFAULT 0,
FOREIGN KEY (user_id) REFERENCES users(id)
);You can test the API endpoints using the included test.rest file with the REST Client extension in VS Code, or use tools like Postman or curl.
POST http://localhost:3000/auth/register
Content-Type: application/json
{
"username": "your-username",
"password": "your-password"
}- Password Hashing: All passwords are hashed using bcrypt with salt rounds
- JWT Authentication: Secure token-based authentication
- Input Validation: Server-side validation for all inputs
- SQL Injection Prevention: Prepared statements protect against SQL injection
- Foreign Key Constraints: Database integrity with proper relationships
pnpm dev- Start development server with hot reloadpnpm build- Build the project for productionpnpm start- Start the production serverpnpm check- Run TypeScript type checking
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the ISC License - see the LICENSE file for details.
JimmFly
- GitHub: @JimmFly
- Express.js community for excellent documentation
- SQLite for providing a lightweight database solution
- The TypeScript team for making JavaScript development more robust
⭐ If you found this project helpful, please give it a star!