A simple Node.js CRUD API using Express and MySQL, designed for learning and practicing backend fundamentals.
-
Clone the repository
git clone https://github.com/killflex/express-mysql-practice.git cd express-mysql-practice -
Install dependencies
npm install
-
Create
.envfileDuplicate the provided
env.examplefile and rename it:cp env.example .env
Fill in your MySQL credentials and database info.
-
Start your MySQL server.
-
Ensure your
.envis correctly configured. -
Start the server:
npm start
-
Access the API via:
http://localhost:3000
Returns a list of all users.
Response:
[
{
"id": 1,
"name": "John Doe",
"email": "john@example.com"
}
]Returns a single user by ID.
Response:
{
"id": 2,
"name": "Jane Smith",
"email": "jane@example.com"
}Creates a new user.
Request:
{
"name": "New User",
"email": "newuser@example.com"
}Response:
{
"message": "User created successfully"
}Updates a user's details.
Request:
{
"name": "Updated Name",
"email": "updated@example.com"
}Response:
{
"message": "User updated successfully"
}Deletes a user by ID.
Response:
{
"message": "User deleted successfully"
}- RESTful API using Express
- MySQL integration with async/await
- Environment-based configuration
- Clean project structure
Edit the .env file to configure your database connection:
DB_HOST=localhost
DB_USER=root
DB_PASSWORD=yourpassword
DB_NAME=practice_db
PORT=3000- Ensure your MySQL server is running.
- Check that the database and tables exist.
- Confirm that
.envvalues are correct. - Look for console errors when the server starts.
- @killflex – Original author