Backend API for Arts project built with Node.js, TypeScript, Express.js, and MariaDB.
- ✅ TypeScript for type safety
- ✅ Express.js for API endpoints
- ✅ MariaDB database with connection pooling
- ✅ CORS enabled
- ✅ Environment configuration
- ✅ Error handling middleware
- ✅ ESLint & Prettier for code quality
- ✅ Hot reload with Nodemon
- Node.js (v17)
- npm or yarn
- MariaDB server running
-
Clone the repository or navigate to the project directory
-
Install dependencies:
npm install- Create
.envfile from the example:
cp .env.example .env- Update the
.envfile with your MariaDB credentials:
PORT=3000
NODE_ENV=development
DB_HOST=localhost
DB_PORT=3306
DB_USER=your_username
DB_PASSWORD=your_password
DB_NAME=artsdb
DB_CONNECTION_LIMIT=10
- Create the database in MariaDB:
CREATE DATABASE artsdb;Run the development server with hot reload:
npm run devThe server will start on http://localhost:3000 (or the PORT specified in .env)
Build the TypeScript code:
npm run buildStart the production server:
npm startnpm run dev- Start development server with hot reloadnpm run build- Compile TypeScript to JavaScriptnpm start- Start production servernpm run lint- Run ESLintnpm run lint:fix- Fix ESLint errorsnpm run format- Format code with Prettier
GET /api/health
Returns server status and timestamp.
artsbackend/
├── src/
│ ├── config/
│ │ └── database.ts # Database configuration
│ ├── controllers/
│ │ └── healthController.ts
│ ├── middleware/
│ │ └── errorHandler.ts # Error handling middleware
│ ├── routes/
│ │ └── index.ts # Route definitions
│ └── server.ts # Express server setup
├── .env.example # Environment variables template
├── .eslintrc.json # ESLint configuration
├── .gitignore
├── .prettierrc.json # Prettier configuration
├── nodemon.json # Nodemon configuration
├── package.json
├── tsconfig.json # TypeScript configuration
└── README.md
| Variable | Description | Default |
|---|---|---|
| PORT | Server port | 3000 |
| NODE_ENV | Environment mode | development |
| DB_HOST | MariaDB host | localhost |
| DB_PORT | MariaDB port | 3306 |
| DB_USER | Database user | root |
| DB_PASSWORD | Database password | - |
| DB_NAME | Database name | artsdb |
| DB_CONNECTION_LIMIT | Max connections | 10 |
ISC