Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Express MySQL Practice

A simple Node.js CRUD API using Express and MySQL, designed for learning and practicing backend fundamentals.


📚 Table of Contents


📦 Installation

  1. Clone the repository

    git clone https://github.com/killflex/express-mysql-practice.git
    cd express-mysql-practice
  2. Install dependencies

    npm install
  3. Create .env file

    Duplicate the provided env.example file and rename it:

    cp env.example .env

    Fill in your MySQL credentials and database info.


🚀 Usage

  1. Start your MySQL server.

  2. Ensure your .env is correctly configured.

  3. Start the server:

    npm start
  4. Access the API via: http://localhost:3000


📡 API Endpoints

GET /users

Returns a list of all users.

Response:

[
  {
    "id": 1,
    "name": "John Doe",
    "email": "john@example.com"
  }
]

GET /users/:id

Returns a single user by ID.

Response:

{
  "id": 2,
  "name": "Jane Smith",
  "email": "jane@example.com"
}

POST /users

Creates a new user.

Request:

{
  "name": "New User",
  "email": "newuser@example.com"
}

Response:

{
  "message": "User created successfully"
}

PUT /users/:id

Updates a user's details.

Request:

{
  "name": "Updated Name",
  "email": "updated@example.com"
}

Response:

{
  "message": "User updated successfully"
}

DELETE /users/:id

Deletes a user by ID.

Response:

{
  "message": "User deleted successfully"
}

✨ Features

  • RESTful API using Express
  • MySQL integration with async/await
  • Environment-based configuration
  • Clean project structure

⚙️ Configuration

Edit the .env file to configure your database connection:

DB_HOST=localhost
DB_USER=root
DB_PASSWORD=yourpassword
DB_NAME=practice_db
PORT=3000

📦 Dependencies


🛠 Troubleshooting

  • Ensure your MySQL server is running.
  • Check that the database and tables exist.
  • Confirm that .env values are correct.
  • Look for console errors when the server starts.

👨‍💻 Contributors


About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages