This demonstrates the cconnection of MySQL database and Node.js to create a simple API
- Node.js installed
- MySQL installed and running
- A code editor, like Visual Studio Code
-
Clone the repository
-
Initialize the node.js environment
npm init -y -
Install the necessary dependancies
npm install express mysql2 dotenv nodemon -
Create a
server.jsand.envfiles -
Basic
server.jssetupconst express = require('express') const app = express() // Question 1 goes here // Question 2 goes here // Question 3 goes here // Question 4 goes here // listen to the server const PORT = 3000 app.listen(PORT, () => { console.log(`server is runnig on http://localhost:${PORT}`) })
nodemon server.js
DB_USERNAME=root
DB_HOST=localhost
DB_PASSWORD=your_password
DB_NAME=hospital_dbConfigure the server.js file to access the credentials in the .env to use them in the database connection
Create a GET endpoint that retrieves all patients and displays their:
patient_idfirst_namelast_namedate_of_birth
Create a GET endpoint that displays all providers with their:
first_namelast_nameprovider_specialty
Create a GET endpoint that retrieves all patients by their first name
Create a GET endpoint that retrieves all providers by their specialty