GitHub – almoggutin/Node-Express-REST-API-MySQL-JS-Example: Basic REST API example that is built with Node.js and Express in JavaScript. Database connection with MySQL with mysql2 library.

Node.js Express REST API MySQL JS Example

This REST API example is a basic backend application to test basic API functions with MySQL database.

View Postman Files

About The Application

This REST API example is a basic backend application to test basic API functions with MySQL database.

It is built with Node.js and Express Framework with Javascript. In addition, the applications database is MySQL, with the use of mysql2 library.

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.

The point of this backend application is to test CRUD operations with MySQL database.

(back to top)

Built With

(back to top)

How To Install

Git clone

git clone https://github.com/almoggutin/Node-Express-REST-API-MySQL-JS-Example

Instructions

  • After cloning the the repository run npm i in order to install all the dependencies.
  • 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.
  • In the sql directory, there are sql files that you will need to execute in order to initialize the database.

(back to top)

Available Scripts

In the project directory, you can run:

npm start

Runs the app in the production mode.
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.

npm run dev

Runs the app in the development mode.
Open localhost on the port you decided on in the env variables to view it in the browser.

The API will reload if you make edits with the use of nodemon.

(back to top)

Postman

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.

(back to top)