5.1.3 • Published 12 days ago

configure-express-app v5.1.3

Weekly downloads
-
License
ISC
Repository
-
Last release
12 days ago

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@latest

Features

  • 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
  • Pre-configured Environment Setup:

    • Includes a .env file for environment variables.
  • 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 database directory.

Prerequisites

Ensure you have the following software installed on your system:

Installation

To create a new Express app, follow these steps:

  1. Run the Generator:

    npx configure-express-app@latest
  2. Navigate to Your Project Directory:

    cd your-project-name
  3. Pre Installed Dependencies Automatically

  4. Configure Environment Variables:

    Create a .env file in the root of your project and set your environment variables. A sample .env.example file is provided.

    cp .env.example .env

    Edit the .env file as needed.

  5. Run the Application In Production:

    npm start
  6. Development 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 routes directory. Create new files for different route groups and import them in routes/index.js.

  • Creating Controllers: Implement your business logic in controllers, located in the controllers directory.

  • Using Middleware: Add custom middleware in the middlewares directory.

  • Database Models: Define your database models in the models directory. Ensure your database connection is configured in database/db.js.

  • Environment Variables: Manage configuration settings through the .env file.

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-docs

Replace 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:

  1. Create a New Module:

    • Create a new folder in the /APIDocs/docs directory.
    • Add your endpoint definitions in this new folder.
  2. 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.

5.1.3

12 days ago

5.0.9

16 days ago

5.0.8

16 days ago

5.1.2

16 days ago

5.1.1

16 days ago

5.1.0

16 days ago

5.0.7

3 months ago

5.0.6

3 months ago

5.0.5

3 months ago

5.0.4

3 months ago

5.0.3

3 months ago

5.0.2

3 months ago

5.0.1

3 months ago

5.0.0

3 months ago

4.0.2

5 months ago

3.3.6

9 months ago

4.0.1

8 months ago

4.0.0

8 months ago

3.3.1

9 months ago

3.3.0

9 months ago

3.3.5

9 months ago

3.3.4

9 months ago

3.3.3

9 months ago

3.3.2

9 months ago

3.2.28

2 years ago

3.2.27

2 years ago

3.2.29

1 year ago

3.2.35

1 year ago

3.2.34

1 year ago

3.2.37

1 year ago

3.2.36

1 year ago

3.2.38

1 year ago

3.2.31

1 year ago

3.2.30

1 year ago

3.2.33

1 year ago

3.2.32

1 year ago

3.2.24

2 years ago

3.2.23

2 years ago

3.2.26

2 years ago

3.2.25

2 years ago

3.2.22

2 years ago

3.2.21

2 years ago

3.2.20

2 years ago

3.1.9

2 years ago

3.1.8

2 years ago

3.2.2

2 years ago

3.2.1

2 years ago

3.2.6

2 years ago

3.2.5

2 years ago

3.2.4

2 years ago

3.2.9

2 years ago

3.2.8

2 years ago

3.2.7

2 years ago

3.2.13

2 years ago

3.1.3

2 years ago

3.2.12

2 years ago

3.1.2

2 years ago

3.2.15

2 years ago

3.1.1

2 years ago

3.2.14

2 years ago

3.2.17

2 years ago

3.1.7

2 years ago

3.2.16

2 years ago

3.1.6

2 years ago

3.2.19

2 years ago

3.1.5

2 years ago

3.2.18

2 years ago

3.1.4

2 years ago

3.2.11

2 years ago

3.2.10

2 years ago

3.1.0

2 years ago

3.0.9

2 years ago

3.0.7

2 years ago

3.0.6

2 years ago

3.0.5

2 years ago

3.0.4

2 years ago

3.0.3

2 years ago

3.0.2

2 years ago

3.0.1

2 years ago

3.0.0

2 years ago

2.1.8

2 years ago

2.1.7

2 years ago

2.1.6

2 years ago

2.1.5

2 years ago

2.1.4

2 years ago

2.1.3

2 years ago

2.1.2

2 years ago

2.1.1

2 years ago

1.1.5

2 years ago

1.1.4

2 years ago

1.1.3

2 years ago

1.1.2

2 years ago

1.1.1

2 years ago

1.0.9

2 years ago

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago