This project consists of a Node.js server and a React client, both implemented in TypeScript. The server utilizes Express.js for handling API routes, MySQL for database operations, and Multer or Socket.IO for file uploads.
The client utilizes React for the front-end and Axios or Socket.IO Client for making HTTP requests to the server. Additionally, Tailwind CSS is used for styling the client-side components.
- Express.js
- MySQL
- Multer / Socket.IO
- TypeScript
- Database Table: Before running the server, ensure you have a MySQL database set up. Create a table named
fileswith a column namedname(you can change these names in the code later, but for the current setup, this table structure is necessary).
- File Upload: The server provides an endpoint (
/upload) for uploading files. Uploaded files are stored in thepublic/uploaddirectory with unique filenames generated using a custom function. - Database Connection: The server connects to a MySQL database using environment variables for configuration.
- Unique filenames for uploaded files are generated using a custom function
randomName(), which creates a random string of characters. This ensures uniqueness for each uploaded file.
Create a .env file in the server directory with the following configuration (edit it according to your configuration):
PORT="8081"
MYSQL_HOST="127.0.0.1"
MYSQL_PORT="3306"
MYSQL_DATABASE="db"
MYSQL_USER="root"
MYSQL_PASSWORD=""- React
- Axios / Socket.IO
- TypeScript
- Tailwind CSS
- File Upload: The client provides a simple UI for selecting and uploading files to the server.
- Feedback Messages: Messages are displayed to the user indicating the status of the file upload process (e.g., success or failure).
- When a file is selected for upload, it is sent to the server using an HTTP POST request to the
/uploadendpoint.
- Clone the repository:
git clone https://github.com/lfixas/Upload-Files-Client-Server.git - Chose your prefered configuration between Multer & Axios or Socket.IO:
cd Multerorcd Socket.io - Navigate to the server directory:
cd server - Install dependencies:
npm install - Create a
.envfile and configure environment variables as described above. - Start the server:
npm start - Open another terminal and navigate to the client directory:
cd ../client - Install dependencies:
npm install - Start the client:
npm start - Access the application in your browser at http://localhost:3000 (or another port if specified).
- If you prefer to use Multer for file uploads, you can navigate to the Multer directory:
cd Multer/ - If you prefer to use Socket.io, you can navigate to the Socket.io directory:
cd Socket.io/
- Make sure you have Node.js and MySQL installed on your system.
- Ensure the MySQL server is running and accessible.
- Tailwind CSS is used for styling the client-side components. You can customize the styles by modifying the Tailwind CSS configuration file (
tailwind.config.js) and the CSS classes in the React components.
- Lucas Fixari
- GitHub: github.com/lfixas
This project is licensed under the MIT License.
Feel free to reach out if you have any questions or need further assistance!