This is a Node.js application with a MongoDB docker container that allows you to manually start and stop the database, as well as perform GET and POST requests to retrieve and save data.
Before starting with the installation and setup process, make sure that you have the following prerequisites installed on your system:
- Node.js version 14 or later
- Docker
Follow these steps to install and set up the project:
- Pull Mongo Image from Docker Hub
docker pull mongo
- Clone the repository:
git clone [email protected]:beth-roy/MongoDB-Dockerized-API.git
- Navigate to the project directory:
cd server
- Install the dependencies:
npm install
- Run
node index.js
to start the API endpoints
- Navigate to the project directory:
cd client
from the base folder - Install the dependencies:
npm install
- Run the client using
npm start
To start the MongoDB container, send a GET request to the /mongo/start
endpoint.
To stop the MongoDB container, send a GET request to the /mongo/stop
endpoint.
To check the status of the MongoDB container, send a GET request to the /mongo/status
endpoint.
To retrieve all users from the users collection, send a GET request to the /users/retrieve
endpoint.
To add a new user to the users collection, send a POST request to the /users/add
endpoint with a JSON payload in the following format:
{
"username":"diana",
"password":"password"
}
With these steps, you should now have a Node.js API with a MongoDB database that allows you to start and stop the MongoDB container, check the status of the container, retrieve all users from the users collection, and add a new user to the collection. Please let me know if you have any questions or if you need further assistance.