Skip to content

This is a repository that provides a project skeleton for Node.js applications built with the Express.js framework. It includes a predefined set of middleware and error handling configurations, making it easier to start developing your web applications.

License

Notifications You must be signed in to change notification settings

m7moudGadallah/express-skeleton

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-skeleton

Table of Content

Introduction

This is a project skeleton for building Node.js applications with the Express.js framework. It provides a well-organized structure, predefined middleware, and error handling configurations to jumpstart your web development projects.

Directory Structure

  • src: The main source directory containing the core application code.

    • app.js: The main application file.
    • config: Configuration files for the application.
    • middlewares: Middleware functions used in the application.
      • preMiddlewares.js: Pre-route middlewares, including sanitizers, loggers, security middlewares, body parsing, etc.
      • postMiddlewares.js: Post-route middlewares, including error handling middlewares.
      • customMiddlewares: Custom middlewares created by developers, such as authorization middlewares.
    • public: Directory for static and media files, like images.
    • resources: Resource-specific directories, each containing:
      • resource_name.controller.js: Controller logic for the resource.
      • resource_name.service.js: Service layer for the resource.
      • resource_name.routes.js: Routes configuration for the resource.
    • routes: Main route files, organizing resources under their respective versions (e.g., v1, v2, etc.).
    • utils: Utility modules for the application.
      • APIFeatures.js: Module for parsing and transforming query strings, handling filtration, selection, sorting, and pagination.
      • AppError.js: Module for creating custom error classes.
      • catchAsync.js: Utility for handling asynchronous functions.
      • JsonResponse.js: Module for structuring JSON responses consistently.
  • config: Configuration files.

    • Database.js: A class for managing database connections and exposing functions to connect and disconnect using the singleton design pattern.
    • index.js: Reads environment variables from .env and instantiates the Database class.
  • .env: Contains environment variables used by the application.

  • test: Directory for testing files (not yet implemented in this skeleton).

↑ Top

Prerequisites

  • Node.js and npm installed.

↑ Top

Getting Started

  1. Clone this repository.

  2. Install dependencies with npm install.

  3. Set environment variables in the .env file.

  4. Start the server:

    • Development Mode: Run npm run start:dev to start the server with nodemon for automatic reloading during development.
    • Production Mode: Run npm run start:prod to start the server in production mode.

Testing:

  • Run tests using Jest:
    • npm test: Run tests in the testing environment.
    • npm run test:coverage: Run tests with code coverage report.

↑ Top

Usage

  • Define your routes, controllers, and services in the resources directory.
  • Customize middleware in the middlewares/customMiddlewares directory.
  • Configure database connections in config/Database.js.
  • Implement custom error handling in middlewares/errorHandlers/dberrorcustomizer.

Contributing

Contributions are welcome!

Here is a list of contributors:

License

This project is licensed under the LICENSE.

Contact

For questions or support, please contact Mahmoud Gadallah.

About

This is a repository that provides a project skeleton for Node.js applications built with the Express.js framework. It includes a predefined set of middleware and error handling configurations, making it easier to start developing your web applications.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published