https://github.com/akunna1/api-mysql-node-express
Creating an API using MySQL, 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-mysql-node-express
crud-api database express-js multer mysql node-js
Last synced: 6 months ago
JSON representation
Creating an API using MySQL, 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-mysql-node-express
- Owner: akunna1
- Created: 2024-09-09T15:37:02.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-09-09T16:01:57.000Z (almost 2 years ago)
- Last Synced: 2025-01-22T18:51:29.839Z (over 1 year ago)
- Topics: crud-api, database, express-js, multer, mysql, node-js
- Language: JavaScript
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# API-MySQL-Node-Express
This project demonstrates how to create a social media post API using MySQL, Express.js, and Node.js. The API supports CRUD operations including image upload.
---
## Features
* Create posts with a message and an image URL
* Retrieve all posts or a single post by ID
* Update posts with new messages and images
* Delete posts
---
## Technologies Used
* Node.js
* Express.js
* MySQL
* Multer (for handling image uploads)
* Body-parser (to parse request bodies)
---
## Database Setup
Create the database and posts table:
```sql
CREATE DATABASE social_media_db;
USE social_media_db;
CREATE TABLE posts (
id INT AUTO_INCREMENT PRIMARY KEY,
message VARCHAR(255) NOT NULL,
image_url VARCHAR(255)
);
```
---
## Installation
1. Initialize npm and install dependencies:
```bash
npm init -y
npm install express mysql multer body-parser
```
2. Configure your MySQL connection in your Node.js app.
3. Start the server:
```bash
node index.js
```
---
## 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 with new message and image |
| DELETE | `/posts/:id` | Delete a post by ID |
---
## Notes
* Image uploads are handled with Multer middleware.
* Requests including images must be sent as multipart/form-data.
* Images are saved and the URL stored in the database.
* Message field stores the text content of the post.