This is a basic Node.js and Express.js application that demonstrates how to handle file uploads using the express-fileupload
middleware. With this middleware, you can easily handle file uploads in your Express.js application.
Before you begin, ensure you have the following installed on your machine:
- Node.js: Make sure you have Node.js installed. You can download it from nodejs.org.
Follow these steps to set up and run the application:
-
Clone the repository:
git clone https://github.com/yourusername/express-fileupload-demo.git cd express-fileupload-demo
-
Install dependencies:
npm install
-
Start the application:
node app.js
The application will be running at
http://localhost:3000
.
-
Open your web browser and go to
http://localhost:3000
. -
You will see a simple HTML form for file uploads.
-
Choose a file by clicking the "Choose File" button and then click the "Upload" button.
-
The server will process the file and store it in the
uploads/
directory.
You can configure the application by modifying the config.js
file. This file contains various settings, including the upload directory and allowed file types.
module.exports = {
uploadDir: './uploads', // The directory where uploaded files will be stored.
allowedTypes: ['image/png', 'image/jpeg', 'image/jpg'], // Allowed file types.
};
This project uses the following dependencies:
- express: Fast, unopinionated, minimalist web framework for Node.js.
- express-fileupload: Simple Express middleware for uploading files.
This project is licensed under the MIT License - see the LICENSE file for details.
- Thank you to the developers of express-fileupload for creating this useful middleware.
Feel free to customize and expand upon this basic application to suit your specific needs. If you have any questions or run into issues, please refer to the documentation of the used libraries and feel free to open an issue on GitHub for this project.
Happy coding!