This project is a SQL Data Management Application built using Node.js with Express.js, MySQL, and EJS templating for the front-end. The project allows CRUD (Create, Read, Update, Delete) operations for user records stored in a MySQL database. Faker.js is used to generate mock user data for testing purposes.
This application provides a simple web interface for managing user data stored in a MySQL database. The application allows the following operations:
- Display a list of users
- Add new user records
- Edit existing user records
- View individual user details
- Delete user records
Mock data generation is done using the Faker.js library.
- CRUD Functionality: Full Create, Read, Update, Delete support for user data.
- Mock Data Generation: Generates mock user data using Faker.js.
- Database Integration: Uses MySQL for persistent data storage.
- Templating Engine: Utilizes EJS for rendering server-side HTML templates.
- Routing and Middleware: Express.js is used for routing and handling HTTP requests.
- Node.js: Backend runtime environment
- Express.js: Web framework for Node.js
- MySQL: Database for storing user data
- EJS: Templating engine for rendering HTML
- Faker.js: Library for generating fake data
- Method-Override: Middleware to support HTTP verbs like PUT and DELETE
- UUID: For generating unique identifiers
To run this project locally, follow these steps:
-
Clone the repository:
git clone https://github.com/Anshuman-Jha-01/RESTful-API-with-SQL.git
-
Navigate into the project directory:
cd RESTful-API-with-SQL
-
Install dependencies: Ensure you have Node.js and MySQL installed. Then run:
npm install
-
Set up MySQL: Create a MySQL database named
Home
. You can do this by logging into MySQL and running:CREATE DATABASE Home;
-
Configure MySQL: In both
index.js
andinsertData.js
, enter the MySQL password in the following snippet:password: "your-password"
-
Run the application: Start the Node.js server:
node index.js
-
Insert mock data: To populate the database with fake data, run:
node insertData.js
-
Access the application: Open your browser and go to:
http://localhost:8080
- The homepage shows the total number of user records.
- Use the
/user
route to see all users in the database. - Add a new user via the
/new
route. - Edit a user by navigating to
/user/edit/:id
. - Delete a user by navigating to
/user/delete/:id
.
- GET
/
: Homepage displaying the number of users - GET
/user
: Displays all users - POST
/user
: Adds a new user - GET
/user/:id
: Displays a specific user - PATCH
/user/:id
: Edits user data - DELETE
/user/:id
: Deletes a user
/views # EJS templates for rendering UI
/public # Static files (CSS, JS, images)
index.js # Main server file
insertData.js # Script to populate database with mock data
package.json # Project metadata and dependencies
This project is licensed under the ISC License.