This project is a simple CRUD API built with Node.js and Express, and it can be easily set up using Docker Compose for containerization. It follows the MVC (Model-View-Controller) architecture and utilizes the singleton pattern for the database.
- Docker (latest version)
- Docker Compose (latest version)
- Node (v14) (not required if docker is used)
A working example of the project can be found at https://52.91.186.141/person
- Clone the repository:
git clone https://github.com/Eyob94/mereb_node_project.git
- Navigate to the project directory:
cd mereb_node_project
- Start the application using Docker Compose:
docker-compose up --build -d
OR
node index.js
The API will be accessible at http://localhost
or https://localhost
(if you create an SSL certificate) if docker is used or at port 3000 if it isn't.
In order to run the unit tests created for this app, you can run
npm test
- GET
/person
- Retrieve all persons - GET
/person/:personId
- Retrieve a specific person by ID - POST
/person
- Create a new person - PUT
/person/:personId
- Update a specific person by ID - DELETE
/person/:personId
- Delete a specific person by ID
The project follows a structured directory layout:
├── person
│ └── middleware
│ └── ...
│ └── person.controller.js
│ └── person.service.js
│ └── person.schema.js
├── middleware
│ └── ...
├── constants
│ └── ...
├── database
│ └── ...
├── interface
│ └── ...
├── utils
│ └── ...
├── .github
│ └── ...
├── app.js
├── index.js
├── Dockerfile
└── docker-compose.yml
└── ...
person
: Contains the logic for handling API requests and responses for the/person
endpoint.middleware
: Defines the global middlewares.database
: Defines the singleton database connection.interface
: Provides the global schemas.utils
: Provides utility functions for the app.constants
: Parses and validates global constants like env variables.app.js
: Sets up the Express App class that will be used to setup the controllers and create the server.index.js
: Entry point to start the server.Dockerfile
: Specifies the instructions to build the Docker image.docker-compose.yml
: Defines the services and dependencies for Docker Compose.
The docker-compose.yml
file defines the services and dependencies for Docker Compose.