https://github.com/akunna1/api-mongodb-node-express-
Creating an API using MongoDB, Express.js, and Node.js to create a social media post with CRUD operations. The post includes a message and an image upload
https://github.com/akunna1/api-mongodb-node-express-
crud-api database express-js mongodb mongoose multer node-js
Last synced: about 2 months ago
JSON representation
Creating an API using MongoDB, Express.js, and Node.js to create a social media post with CRUD operations. The post includes a message and an image upload
- Host: GitHub
- URL: https://github.com/akunna1/api-mongodb-node-express-
- Owner: akunna1
- Created: 2024-09-09T15:54:46.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-09-09T16:03:00.000Z (about 1 year ago)
- Last Synced: 2025-04-05T16:33:38.002Z (6 months ago)
- Topics: crud-api, database, express-js, mongodb, mongoose, multer, node-js
- Language: JavaScript
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# API-MongoDB-Node-Express
This project is a simple social media post API built using MongoDB, Express.js, and Node.js. It supports CRUD operations including image upload for posts.
---
## Features
* Create social media posts with a message and image
* Read all posts or a single post by ID
* Update posts with new messages and images
* Delete posts
* Uses MongoDB database: `social_media_db`
* Posts stored in the `posts` collection---
## Technologies Used
* Node.js
* Express.js
* MongoDB
* Mongoose (for schema and database modeling)
* Multer (for image upload handling)
* Body-parser (to parse incoming request bodies)---
## Installation
1. Initialize npm and install dependencies:
```bash
npm init -y
npm install express mongoose multer body-parser
```2. Run your MongoDB server locally or use a MongoDB cloud instance.
3. Start the server:
```bash
node index.js
```*(Assuming your main file is named `index.js`)*
---
## MongoDB Schema (using Mongoose)
* The post schema is defined in code, no need to create schema manually in MongoDB shell.
* Contains fields for message (text) and image (file info).---
## API Endpoints
| Method | Endpoint | Description |
| ------ | ------------ | ---------------------------- |
| POST | `/posts` | Create a new post with image |
| GET | `/posts` | Retrieve all posts |
| GET | `/posts/:id` | Retrieve a single post by ID |
| PUT | `/posts/:id` | Update a post and its image |
| DELETE | `/posts/:id` | Delete a post by ID |---
## Notes
* Image uploads handled using Multer middleware.
* Requests with images must be sent as multipart/form-data.
* Message is a text string associated with each post.---
This API serves as a foundation for building social media applications with image support and basic CRUD functionality.