Creating Example Rest API using Express, MySQL, Multer.
# 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)
-
Clone this repository to your local machine:
git clone https://github.com/Hafizcode02/restapi-mysql.git
-
Navigate to the project directory:
cd restapi-mysql
-
Install the dependencies:
npm install
before starting running the application, set env file based on your needs:
PORT=XXXX
DB_HOST=XXX
DB_USERNAME=XXXX
DB_PASSWORD=XXXX
DB_NAME=XXXX
SQL File is in folder, just import it..
To start the Express.js server and run the file upload example, use the following command:
npm start run-dev
This will start the server on http://localhost:ENV_PORT or in port 8004.
- The file upload route is configured at
/upload
. - Only specific file types (JPEG, PNG, and PDF) are allowed.
[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/
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