Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/m7moudgadallah/express-skeleton
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.
https://github.com/m7moudgadallah/express-skeleton
custom-error-handling expressjs jest nodejs project-skeleton unit-testing
Last synced: about 1 month ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/m7moudgadallah/express-skeleton
- Owner: m7moudGadallah
- License: mit
- Created: 2023-09-24T19:16:32.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2023-10-05T23:16:49.000Z (over 1 year ago)
- Last Synced: 2024-11-08T13:41:22.382Z (3 months ago)
- Topics: custom-error-handling, expressjs, jest, nodejs, project-skeleton, unit-testing
- Language: JavaScript
- Homepage:
- Size: 395 KB
- Stars: 1
- Watchers: 1
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# express-skeleton
## Table of Content
- [express-skeleton](#express-skeleton)
- [Table of Content](#table-of-content)
- [Introduction](#introduction)
- [Directory Structure](#directory-structure)
- [Prerequisites](#prerequisites)
- [Getting Started](#getting-started)
- [Usage](#usage)
- [Contributing](#contributing)
- [License](#license)
- [Contact](#contact)## 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](#express-skeleton)**
## Prerequisites
- Node.js and npm installed.
**[↑ Top](#express-skeleton)**
## 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](#express-skeleton)**
## 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:**
- Mahmoud Gadallah ([Github](https://github.com/m7moudGadallah) | [Linkdin](https://www.linkedin.com/in/m7moudgadallah/))
- Marwan Radwan ([Github](https://github.com/MarwanRadwan7) | [Linkdin](https://www.linkedin.com/in/marwan-radwan))
- Mohamed AboElnasr ([Github](https://github.com/MohamedAboElnaser) | [Linkdin](https://www.linkedin.com/in/mohamed-aboelnasr-473b9a1b1/))## License
This project is licensed under the [LICENSE](LICENSE).
## Contact
For questions or support, please contact [Mahmoud Gadallah](https://www.linkedin.com/in/m7moudgadallah/).