A modern, full-stack todo list web application with a Node.js/Express backend and MariaDB database hosted on OSaaS (Open Source Cloud).
- Modern UI: Clean, responsive interface with smooth animations
- Full CRUD Operations: Create, read, update, and delete todos
- Smart Filtering: View all todos, only active, or only completed
- RESTful API: Well-structured backend with proper error handling
- Production Ready: Environment-based configuration and proper database connection pooling
- MariaDB Database: Persistent storage with optimized schema
- HTML5
- CSS3 (Modern design with CSS Grid/Flexbox)
- Vanilla JavaScript (ES6+)
- Node.js
- Express.js
- MariaDB (via mariadb npm package)
- CORS enabled
- MariaDB hosted on OSaaS
- Optimized table structure with indexes
- Node.js 16+ and npm
- MariaDB database on OSaaS (see setup instructions below)
- Git (optional)
- Go to the OSaaS web interface
- Create a service secret for your database root password:
- Navigate to secrets section
- Create a new secret with key
rootpasswordand your desired password
- Create a new MariaDB instance:
- Click "Create dbserver"
- Select the MariaDB service
- Configure your instance settings
- Wait for the instance to reach "Running" status
- Note the IP address and port from the service instance card
import { Context } from '@osaas/client-core';
import { createLinuxserverDockerMariadbInstance } from '@osaas/client-services';
const ctx = new Context();
const config = {
name: 'todo-db',
// additional configuration
};
const instance = await createLinuxserverDockerMariadbInstance(ctx, config);
console.log('Database URL:', instance.url);For more details, see the OSaaS MariaDB Documentation.
- Clone or download this repository:
cd todo-app- Install dependencies:
npm install- Configure environment variables:
cp .env.example .env- Edit
.envwith your MariaDB credentials:
DB_HOST=your-mariadb-host
DB_PORT=your-mariadb-port
DB_USER=root
DB_PASSWORD=your-root-password
DB_NAME=todo_db
PORT=3000
NODE_ENV=development- Initialize the database:
npm run init-dbThis will:
- Create the
todo_dbdatabase - Create the
todostable with proper schema - Insert sample todos
npm run devnpm startThe application will be available at:
- Frontend: http://localhost:3000
- API: http://localhost:3000/api/todos
- Health Check: http://localhost:3000/api/health
http://localhost:3000/api
GET /todosResponse:
[
{
"id": 1,
"title": "Buy groceries",
"completed": false,
"created_at": "2025-12-03T10:30:00.000Z"
}
]GET /todos/:idResponse:
{
"id": 1,
"title": "Buy groceries",
"completed": false,
"created_at": "2025-12-03T10:30:00.000Z"
}POST /todos
Content-Type: application/json
{
"title": "New todo item"
}Response:
{
"id": 2,
"title": "New todo item",
"completed": false,
"created_at": "2025-12-03T10:35:00.000Z"
}PUT /todos/:id
Content-Type: application/json
{
"title": "Updated title",
"completed": true
}Response:
{
"id": 1,
"title": "Updated title",
"completed": true,
"created_at": "2025-12-03T10:30:00.000Z"
}DELETE /todos/:idResponse:
204 No Content
GET /healthResponse:
{
"status": "ok",
"database": "connected",
"timestamp": "2025-12-03T10:40:00.000Z"
}CREATE TABLE todos (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(255) NOT NULL,
completed BOOLEAN DEFAULT false,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
INDEX idx_completed (completed),
INDEX idx_created_at (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;todo-app/
├── backend/
│ ├── config/
│ │ └── database.js # Database connection and pool
│ ├── routes/
│ │ └── todos.js # Todo API routes
│ ├── server.js # Express server setup
│ └── init-db.js # Database initialization script
├── frontend/
│ ├── index.html # Main HTML file
│ ├── styles.css # Styles and responsive design
│ └── app.js # Frontend JavaScript logic
├── .env.example # Environment variables template
├── .gitignore # Git ignore rules
├── package.json # Dependencies and scripts
└── README.md # This file
- All API endpoints include comprehensive error handling
- Frontend displays user-friendly error messages
- Database connection failures are gracefully handled
- Input validation on both frontend and backend
- SQL injection prevention via parameterized queries
- XSS prevention with HTML escaping
- CORS configuration for development
- Database connection pooling
- Indexed database queries
- Efficient frontend rendering
- Minimal dependencies
To deploy this application to OSaaS:
- Ensure your MariaDB instance is provisioned on OSaaS
- Update your
.envfile with the production database credentials - Set
NODE_ENV=productionin your environment - Follow OSaaS deployment documentation for Node.js applications
- Run
npm run init-dbonce to initialize the database - Start the server with
npm start
# Test database connection
npm run init-dbIf you see connection errors:
- Verify your database credentials in
.env - Ensure MariaDB instance is running on OSaaS
- Check firewall/network settings
- Verify the host and port are correct
# Change PORT in .env file or:
PORT=3001 npm start# Clear node_modules and reinstall
rm -rf node_modules package-lock.json
npm install- OSaaS Documentation
- OSaaS MariaDB Service
- OSaaS JavaScript SDK
- Express.js Documentation
- MariaDB Node.js Connector
ISC
For issues related to:
- Application: Check the troubleshooting section above
- OSaaS Platform: Visit OSaaS Documentation
- Database: Review MariaDB logs and connection settings