https://github.com/hafizcode02/simple-restapi-mysql
Creating Example of Rest API using Express, MySQL, Multer, Express-Validator
https://github.com/hafizcode02/simple-restapi-mysql
express-js express-validator multer mysql
Last synced: about 1 month ago
JSON representation
Creating Example of Rest API using Express, MySQL, Multer, Express-Validator
- Host: GitHub
- URL: https://github.com/hafizcode02/simple-restapi-mysql
- Owner: hafizcode02
- Created: 2023-11-13T03:00:05.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2023-12-01T13:46:43.000Z (about 2 years ago)
- Last Synced: 2025-02-03T14:47:50.137Z (about 1 year ago)
- Topics: express-js, express-validator, multer, mysql
- Language: JavaScript
- Homepage:
- Size: 381 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# restapi-mysql
Creating Example Rest API using Express, MySQL, Multer.
```markdown
# Express.js simple rest api with mysql and Multer for uploading image.
This is a simple example of an Express.js rest api with mysql and Multer for uploading image..
## Prerequisites
Before running the application, make sure you have the following installed on your machine:
- [Node.js](https://nodejs.org/)
- [npm](https://www.npmjs.com/) (Node Package Manager)
```
## Getting Started
1. Clone this repository to your local machine:
```bash
git clone https://github.com/Hafizcode02/restapi-mysql.git
```
2. Navigate to the project directory:
```bash
cd restapi-mysql
```
3. Install the dependencies:
```bash
npm install
```
## SETTING UP .ENV File
before starting running the application, set env file based on your needs:
```bash
PORT=XXXX
DB_HOST=XXX
DB_USERNAME=XXXX
DB_PASSWORD=XXXX
DB_NAME=XXXX
```
SQL File is in folder, just import it..
## Running the Application
To start the Express.js server and run the file upload example, use the following command:
```bash
npm start run-dev
```
This will start the server on [http://localhost:ENV_PORT](http://localhost:ENV_PORT) or in port 8004.
## File Upload
- The file upload route is configured at `/upload`.
- Only specific file types (JPEG, PNG, and PDF) are allowed.
## API Endpoint List
```bash
[POST] your-site/users
[GET] your-site/users
[GET] your-site/users/:id
[PATCH] your-site/users/:id
[DELETE] your-site/users/:id
[POST] your-site/upload/
```
## Your Body Data
```
For POST, PATCH users use raw JSON type
{
"name" : "Argh Satrio",
"email" : "landa@gmail.com",
"address": "World"
}
For POST images/files, use form-data type.
photo : abcd.jpg
```