A file metadata microservice built as part of the FreeCodeCamp Back End Development and APIs certification. This API allows users to upload files and retrieve metadata information including file name, type, and size.
- File Upload: Upload files using multipart form data
- Metadata Extraction: Extract file name, MIME type, and size
- RESTful API: Simple and clean API endpoints
- File Type Support: Supports various file types and formats
- Real-time Processing: Instant file analysis upon upload
- Node.js: Runtime environment
- Express.js: Web framework
- Multer: Middleware for handling multipart/form-data
- CORS: Cross-origin resource sharing
- dotenv: Environment variable management
-
Clone the repository
git clone https://github.com/aliammari1/freecodecamp-filemetadata-project.git cd freecodecamp-filemetadata-project
-
Install dependencies
npm install
-
Set up environment variables
cp sample.env .env # Edit .env with your configuration
-
Start the server
npm start
-
Open your browser
Navigate to http://localhost:3000
- POST
/api/fileanalyse
- Content-Type:
multipart/form-data
- Form field:
upfile
Example Response:
{
"name": "example.txt",
"type": "text/plain",
"size": 1024
}
- GET
/api/fileanalyse
Example Response:
{
"name": "example.txt",
"type": "text/plain",
"size": 1024
}
- Navigate to the main page
- Select a file using the file input
- Click "Upload" to analyze the file
- View the metadata response
# Upload a file
curl -X POST -F "upfile=@/path/to/your/file.txt" http://localhost:3000/api/fileanalyse
# Get last uploaded file info
curl http://localhost:3000/api/fileanalyse
freecodecamp-filemetadata-project/
├── public/ # Static files (CSS, client-side JS)
├── views/ # HTML templates
├── uploads/ # Temporary file storage
├── index.js # Main server file
├── package.json # Dependencies and scripts
├── sample.env # Environment variables template
└── README.md # Project documentation
The application uses the following environment variables:
PORT
: Server port (default: 3000)
Test the API using various file types:
# Test with different file types
curl -X POST -F "[email protected]" http://localhost:3000/api/fileanalyse
curl -X POST -F "[email protected]" http://localhost:3000/api/fileanalyse
curl -X POST -F "[email protected]" http://localhost:3000/api/fileanalyse
The API returns file metadata in the following format:
interface FileMetadata {
name: string; // Original filename
type: string; // MIME type
size: number; // File size in bytes
}
npm start
- Set environment variables
- Install production dependencies:
npm ci --only=production
- Start the application:
npm start
This project is licensed under the MIT License - see the LICENSE file for details.
- Fork the repository
- Create a feature branch:
git checkout -b feature-name
- Commit your changes:
git commit -am 'Add feature'
- Push to the branch:
git push origin feature-name
- Submit a pull request
This project is part of the FreeCodeCamp curriculum:
nodejs
express
multer
file-upload
microservice
freecodecamp
backend
api
javascript
Ali Ammari
- GitHub: @aliammari1
- Portfolio: aliammari.netlify.app
⭐ Star this repository if you found it helpful!