This is a simple Node.js application for managing users with a SQL database. The app uses Express.js for the server, EJS for templating, and a SQL database for data storage. It provides basic CRUD (Create, Read, Update, Delete) operations for user management.
- List all users
- Add a new user
- Edit user details
- Delete a user
- Password-protected edit and delete actions
- Uses UUIDs for user IDs
- Generates fake users for testing (via Faker.js)
index.js # Main server file
package.json # Project dependencies and scripts
schema.sql # SQL schema for database setup
views/ # EJS templates for UI
├── delete.ejs
├── edit.ejs
├── home.ejs
├── new.ejs
└── showusers.ejs
- Home Page: Shows the total number of users in the database.
- Show Users: Lists all users with options to edit or delete each user.
- Add User: Form to add a new user (email, username, password required).
- Edit User: Edit a user's username (requires password confirmation).
- Delete User: Delete a user (requires password confirmation).
- Node.js (v14 or higher recommended)
- MySQL database (or compatible with
mysql2)
- Clone the repository or download the source code.
- Install dependencies:
npm install
- Set up your database using the
schema.sqlfile:- Create a database (default:
delta_app). - Run the SQL in
schema.sqlto create theusertable.
- Create a database (default:
- Configure your database connection in
index.js:- Update
host,user,password, anddatabaseas needed.
- Update
- Start the server:
node index.js
- Open your browser and go to
http://localhost:8080(or the port specified in your code).
- Add User: Go to
/user/newand fill out the form. - View Users: Go to
/userto see all users. - Edit User: Click "Edit username" next to a user, enter new username and password.
- Delete User: Click "Delete" next to a user, enter password to confirm.
POST /user/new
Body: email, username, password
- Database connection errors: Check your MySQL server is running and credentials in
index.jsare correct. - Port in use: Change the port in
index.jsif 3000 is occupied. - Password errors: Edit and delete actions require the correct password for the user.
Database connection is configured in index.js:
const connection = mysql.createConnection({
host: 'localhost',
user: 'root',
database: 'delta_app',
password: 'your_password_here'
});You may use environment variables for sensitive data in production.
-
express: Web server framework
-
ejs: Templating engine
-
mysql2: MySQL database driver
-
method-override: Supports HTTP verbs like PATCH/DELETE in forms
-
@faker-js/faker: Generates fake user data for testing
-
uuid: Generates unique user IDs
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.