This is a simple REST API built with Node.js and Express, using MongoDB as the database. It provides endpoints for managing subscribers.
Before running this project, make sure you have the following installed:
- Node.js
- MongoDB
- Docker (optional, for running with Docker Compose)
-
Clone the repository:
git clone https://github.com/zdbrig/nodemongo.git cd nodemongo
-
Install the dependencies:
npm install
-
Set up the environment variables:
-
Create a
.env
file in the root directory of the project. -
Add the following variable to the
.env
file:DATABASE_URL=mongodb://localhost:27017/myapp
Replace
myapp
with your desired database name.
-
-
Start the server:
npm start
The server will start running at
http://localhost:3000
.
The following endpoints are available:
GET /subscribers
: Get all subscribers.GET /subscribers/:id
: Get a specific subscriber by ID.POST /subscribers
: Create a new subscriber.PATCH /subscribers/:id
: Update a subscriber by ID.DELETE /subscribers/:id
: Delete a subscriber by ID.
To run the application using Docker Compose, follow these steps:
-
Make sure you have Docker and Docker Compose installed on your machine.
-
Build and run the containers:
docker-compose up --build
This will start the Node.js application and MongoDB containers.
-
Access the application at
http://localhost:3000
.
You can test the API endpoints using a tool like Postman or by running the provided index.js
script.
To run the index.js
script:
-
Make sure you have the
axios
package installed:npm install axios
-
Run the script:
node index.js
The script will make requests to the API endpoints and log the responses.
Contributions are welcome! If you find any issues or have suggestions for improvements, please open an issue or submit a pull request.
This project is licensed under the MIT License.