|
| 1 | +<div id="top"></div> |
| 2 | + |
| 3 | +<h1 align="center">Node.js Express REST API MySQL JS Example</h1> |
| 4 | + |
| 5 | +<div align="center"> |
| 6 | + <p align="center"> |
| 7 | + This REST API example is a basic backend application to test basic API functions with MySQL database. |
| 8 | + </p> |
| 9 | + <a href="https://www.postman.com/workspace/node-js-express-mysql-rest-api-example/overview">View Postman Files</a> |
| 10 | +</div> |
| 11 | + |
| 12 | +<!-- TABLE OF CONTENTS --> |
| 13 | +<details> |
| 14 | + <summary>Table of Contents</summary> |
| 15 | + <ol> |
| 16 | + <li> |
| 17 | + <a href="#about-the-application">About The Application</a> |
| 18 | + <ul> |
| 19 | + <li><a href="#built-with">Built With</a></li> |
| 20 | + </ul> |
| 21 | + </li> |
| 22 | + <li><a href="#how-to-install">How To Install</a></li> |
| 23 | + <li><a href="#available-scripts">Available Scripts</a></li> |
| 24 | + <li><a href="#postman">Postman</a></li> |
| 25 | + </ol> |
| 26 | +</details> |
| 27 | + |
| 28 | +<!-- ABOUT THE APPLICATION --> |
| 29 | + |
| 30 | +## About The Application |
| 31 | + |
| 32 | +This REST API example is a basic backend application to test basic API functions with MySQL database. |
| 33 | + |
| 34 | +It is built with Node.js and Express Framework with Javascript. In addition, the applications database is MySQL, with the use of mysql2 library. |
| 35 | + |
| 36 | +In the applicaiton we can manage user data, such as create/edit/delete a user. In addition, we can get all the users in the database. |
| 37 | + |
| 38 | +The point of this backend application is to test CRUD operations with MySQL database. |
| 39 | + |
| 40 | +<p align="right">(<a href="#top">back to top</a>)</p> |
| 41 | + |
| 42 | +### Built With |
| 43 | + |
| 44 | +- [Node.js](https://nodejs.org/en/) |
| 45 | +- [Express](https://expressjs.com/) |
| 46 | +- [Cors](https://www.npmjs.com/package/cors) |
| 47 | +- [MySQL2](https://www.npmjs.com/package/mysql2) |
| 48 | + |
| 49 | +<p align="right">(<a href="#top">back to top</a>)</p> |
| 50 | + |
| 51 | +<!-- INSTALLATION INSTRUCTIONS --> |
| 52 | + |
| 53 | +## How To Install |
| 54 | + |
| 55 | +**Git clone** |
| 56 | + |
| 57 | +``` |
| 58 | +git clone https://github.com/almoggutin/Node-Express-REST-API-MySQL-JS-Example |
| 59 | +``` |
| 60 | + |
| 61 | +**Instructions** |
| 62 | + |
| 63 | +- After cloning the the repository run `npm i` in order to install all the dependencies. |
| 64 | +- Create an env file in the root of the project named .env and fill in the follwing variables: PORT, DB_HOST, DB_PORT, DB_USERNAME, DB_USERNAME_PASSWORD, DB_NAME. |
| 65 | +- In the sql directory, there are sql files that you will need to execute in order to initialize the database. |
| 66 | + |
| 67 | +<p align="right">(<a href="#top">back to top</a>)</p> |
| 68 | + |
| 69 | +<!-- AVAILABLE SCRIPTS --> |
| 70 | + |
| 71 | +## Available Scripts |
| 72 | + |
| 73 | +In the project directory, you can run: |
| 74 | + |
| 75 | +### `npm start` |
| 76 | + |
| 77 | +Runs the app in the production mode.\ |
| 78 | +However, this script is only meant to be run when deploying the application. The application is built, where you need to setup the env variables on the machine that you will be hosting it on or on a web hosting service, unlike in development mode. |
| 79 | + |
| 80 | +### `npm run dev` |
| 81 | + |
| 82 | +Runs the app in the development mode.\ |
| 83 | +Open localhost on the port you decided on in the env variables to view it in the browser. |
| 84 | + |
| 85 | +The API will reload if you make edits with the use of nodemon. |
| 86 | + |
| 87 | +<p align="right">(<a href="#top">back to top</a>)</p> |
| 88 | + |
| 89 | +<!-- POSTMAN --> |
| 90 | + |
| 91 | +## Postman |
| 92 | + |
| 93 | +If you would like to run the files locally on your machine in the postman desktop application, included in the repository, in the `postman` directory all the files so you can import them. In addition you will have to configure env variables in postman so that you will be able to test properly everything. |
| 94 | + |
| 95 | +<div align="center"> |
| 96 | + <img src="./assets/postman/postman-global-env-variables.png" alt="Postman global env variables."/> |
| 97 | + <img src="./assets/postman/postman-jobs-env-variables.png" alt="Postman admin env variables."/> |
| 98 | +</div> |
| 99 | + |
| 100 | +<p align="right">(<a href="#top">back to top</a>)</p> |
0 commit comments