configure-express-app v5.1.3
Express App Generator
Welcome to the Express App Generator! This tool helps you quickly set up an Express application with pre-configured middleware and optional database connections.
npx configure-express-app@latestFeatures
- Auto-detect Node.js version: Automatically adjusts settings based on the installed Node.js version.
Example:
- In node version 20 don't need this env import, Node js supports .env default. Automatically added (Node.js <= 18)
require('dotenv').config(); - Auto detect node.js version and automatically added (Node.js >= 20)
node --env-file=.env server.js
- In node version 20 don't need this env import, Node js supports .env default. Automatically added (Node.js <= 18)
Pre-configured Environment Setup:
- Includes a
.envfile for environment variables.
- Includes a
Pre-installed Modules and Middleware:
- Express: Web framework for Node.js.
- Rate Limiter: Middleware to limit repeated requests to public APIs and/or endpoints.
- Nodemon: Automatically restarts the server for development.
- Winston: Logging library for application logs.
- UUID: Generates unique request IDs.
- Compression: Gzip compression for improved performance.
- Helmet: Security middleware for HTTP headers.
- CORS: Middleware to enable Cross-Origin Resource Sharing.
- Body-Parser: Middleware to parse incoming request bodies.
- Error Handling: Standardized error responses.
- HPP: Prevent HTTP Parameter Pollution.
- Request Logging: Logs request body, params, query, and headers.
- Prettier: Code formatter for consistent code style.
.gitignore: Pre-configured to exclude sensitive files and directories.- Swagger: API documentation and testing tool.
Database Configuration:
- Choose from PostgreSQL, MongoDB, or None during setup.
- Sample database connection is created in the
databasedirectory.
Prerequisites
Ensure you have the following software installed on your system:
Installation
To create a new Express app, follow these steps:
Run the Generator:
npx configure-express-app@latestNavigate to Your Project Directory:
cd your-project-namePre Installed Dependencies Automatically
Configure Environment Variables:
Create a
.envfile in the root of your project and set your environment variables. A sample.env.examplefile is provided.cp .env.example .envEdit the
.envfile as needed.Run the Application In Production:
npm startDevelopment Mode:
For development mode with live-reloading:
npm run dev
Project Structure
Your Express app will have the following structure:
Usage
Adding Routes: Define your routes in the
routesdirectory. Create new files for different route groups and import them inroutes/index.js.Creating Controllers: Implement your business logic in controllers, located in the
controllersdirectory.Using Middleware: Add custom middleware in the
middlewaresdirectory.Database Models: Define your database models in the
modelsdirectory. Ensure your database connection is configured indatabase/db.js.Environment Variables: Manage configuration settings through the
.envfile.
Scripts
The following scripts are available:
npm start: Start the application.npm run dev: Start the application in development mode with Nodemon.npm run prettify: prettify your code using Prettier.
Security
- Helmet: Protects against known vulnerabilities by setting HTTP headers appropriately.
- HPP: Prevents HTTP Parameter Pollution.
- Express-Mongo-Sanitize: Prevents NoSQL injection attacks.
API Documentation with Swagger
Swagger is used for API documentation and testing. You can access the Swagger UI at the following URL:
http://localhost:8080/api-docsReplace 8080 with the port your application is running on.
Adding New API Endpoints to Swagger
To add new API endpoints to the Swagger documentation, follow these steps:
Create a New Module:
- Create a new folder in the
/APIDocs/docsdirectory. - Add your endpoint definitions in this new folder.
- Create a new folder in the
Update Swagger Configuration:
- Ensure your new module is included in the Swagger configuration file.
By accessing the Swagger UI, you can view and test all available API endpoints in your application.
Contributing
If you'd like to contribute, please fork the repository and use a feature branch. Pull requests are welcome.
License
This project is licensed under the MIT License. See the LICENSE file for details.
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
8 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
2 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago