Rest API with Node.JS, Express, and MySQL.
- Create a REST API with Node.JS, Express, and MySQL.
- With Node.js framework we can create a server that can be accessed from anywhere, using javascript. It will handle the requests and return the data.
- Express is another framework that can be manage the HTTP verbs and routes.
- MySQL is a database that can be used to store data.
- http://localhost:6969/api/languages/getAll (GET)
- Returns all the data from the database.
- http://localhost:6969/api/languages/getById/:id (GET)
- Returns the data from the database with the id.
- http://localhost:6969/api/languages/addNew (POST) (JSON {"name": varchar, "programmers": int})
- Adds a new language to the database.
- http://localhost:6969/api/languages/updateById/:id (PUT) (JSON {"name": varchar, "programmers": int})
- Updates the data from the database with the id.
- http://localhost:6969/api/languages/deleteById/:id (DELETE)
- Deletes the data from the database with the id.
Setup the project:
- Create files and folders.
- Install dependencies.
- dotenv -> to store the environment variables.
- express -> to create the server with javascript and nodeJS.
- promise-mysql -> to create async connection with database.
- babel/cli -> to compile the code with babel.
- babel/core -> to compile the code with babel.
- babel/preset-env -> to compile the code with babel.
- babel/node -> to compile the code with babel.
- morgan -> to console log the requests.
- nodemon -> to restart the server when the code changes.
- Create the database.
>> npm i dotenv express promise-mysql --save
>> npm i babel/cli babel/core babel/preset-env babel/node morgan nodemon --save-dev
flowchart LR
src([/src]) --> controllers[[/controllers]]
src([/src]) --> database[[/database]]
src([/src]) --> routes[[/routes]]
src([/src]) --> app.js
src([/src]) --> index.js>index.js]
src([/src]) --> config.js
Status:
- Done.