rx-node-express-mysql-skeleton
Scaffold for Node.js Express REST API with MySQL
About
Sourced from arikw/rx-node-express-mysql-skeleton README
Description
Scaffold for Node.js Express REST API with MySQL. This project provides a robust starting point for building scalable and maintainable RESTful APIs using Node.js, Express, and MySQL. It includes a well-defined project structure, essential middleware, and testing configurations to accelerate development.
Features
- Node.js & Express: Fast, unopinionated, minimalist web framework for Node.js.
- MySQL: Relational database management system.
- rx-mysql: An opinionated MySQL client for Node.js. See rx-mysql documentation for setup details.
- Sequelize CLI: Command-line interface for Sequelize ORM, used for database migrations.
- CORS: Cross-Origin Resource Sharing enabled.
- Rate Limiting: Protects against brute-force attacks and misuse.
- Security Middleware: Helmet.js for securing Express apps by setting various HTTP headers.
- Request Validation: Using
express-validatorfor robust input validation. - Centralized Error Handling: Global error handling middleware.
- Authentication Middleware: Example authentication middleware.
- Unit & Integration Tests: Comprehensive testing setup with Mocha, Chai, and Sinon.
- Linting: ESLint for code quality and consistency.
- Husky & Lint-Staged: Git hooks for pre-commit linting and unit testing.
- Docker Support:
Dockerfileanddocker-composeconfigurations for containerized development.
Technologies
- Node.js
- Express
- MySQL
- Sequelize
- Mocha
- Chai
- Sinon
- ESLint
- Docker
Setup and Installation
Prerequisites
- Node.js (>=20.0.0)
- npm
- Docker (optional, for containerized development)
- MySQL server
Dev Container Configuration
This project includes a dev container configuration that supports Windows host to container bind mounts using Unison sync for improved performance.
Local Development
Clone the repository:
git clone https://github.com/your-username/rx-node-express-mysql-skeleton.git cd rx-node-express-mysql-skeletonRename Project: Search and replace all occurrences of
rx-devcontainerwith your project's kebab-cased name.Install dependencies:
npm installSet up environment variables: Create a
.envfile in the root directory by copying.env.exampleand filling in the necessary values.cp .env.example .envDatabase Setup: Ensure your MySQL server is running and follow rx-mysql documentation for setup details.
Start the development server:
npm run devThe API will be running at
http://localhost:3452(or your configuredSERVER_ORIGIN).
Docker Development
- Build and run Docker containers:
This will set up the Node.js application and a MySQL database in Docker containers.docker-compose up --build
Environment Variables
The following environment variables can be configured in your .env file:
NODE_ENV: Environment mode (e.g.,development,production,test).SERVER_ORIGIN: The base URL for the API (e.g.,http://localhost:3452).ALLOW_INSECURE_CORS: Set to1to allow insecure CORS (e.g., for local development),0otherwise.RATE_LIMIT_MAX_REQUESTS: Maximum number of requests per window for rate limiting.USE_HTTPS_SERVER: Set to1to enable HTTPS server,0otherwise.SSL_CERT_NAME: Name of the SSL certificate file (ifUSE_HTTPS_SERVERis1).
Available Scripts
In the project directory, you can run:
npm run dev: Starts the application in development mode withnodemonfor automatic restarts.npm start: Starts the application in production mode.npm run test:unit: Runs unit tests.npm run test:integration: Runs integration tests.npm test: Runs both unit and integration tests.npm run coverage: Generates code coverage reports.npm run lint:js: Lints JavaScript files.npm run lint: Runs all linting tasks.npm run db:generate -- --name [migration-name]: Generates a new Sequelize migration file.npm run db:migrate: Applies pending database migrations.npm run db:undo: Undoes the last database migration.npm run db:undo:all: Undoes all database migrations.
Project Structure
.
├── config/ # Configuration files (e.g., database)
├── migrations/ # Sequelize database migration files
├── src/ # Source code
│ ├── common/ # Common project-related utilities and helpers (e.g., request validation, security)
│ ├── controllers/ # Request handlers
│ ├── db/ # Database connection and queries
│ │ └── queries/ # SQL query files
│ ├── loaders/ # Application loaders (e.g., Express, routes, middleware)
│ ├── middlewares/ # Express middleware
│ ├── routes/ # API route definitions
│ ├── utils/ # General-purpose utility functions
│ └── index.js # Main application entry point
├── tests/ # Test files
│ ├── global-fixtures/ # Global test setup
│ ├── helpers/ # Test helpers
│ ├── integration/ # Integration tests
│ └── unit/ # Unit tests
├── .env.example # Example environment variables
├── .dockerignore # Files to ignore in Docker builds
├── Dockerfile # Docker build instructions
├── docker-compose.yml # Docker Compose configuration
├── package.json # Project metadata and dependencies
├── README.md # Project documentation
└── ...
More projects
See all →2020
Extension Page Context Runner
Run functions in page context directly from a browser extension content script
27
2020
Outlook Duplicated Items Remover
A VBA script that finds and moves duplicated items in selected outlook folders
21
2023
RX Input Layout Switcher
Alt+Shift keyboard layout switcher GNOME Shell Extension
16 9.6K
2025
Podman OpenRC Restart Policy Manager
This OpenRC init script manages the automatic startup and shutdown of Podman containers with the `restart-policy=always` on system boot or shutdown
5
2022
Express Response Hooks
Extends Express.js with response hooks
4 149.3K 5.5K/mo
2021
Kids Keyboard Game
Kids Keyboard Game
3