Skip to content

File metadata microservice developed with Node.js and Express for uploading files and retrieving essential metadata such as file name, type, and size in real-time.

Notifications You must be signed in to change notification settings

aliammari1/freecodecamp-filemetadata-project

Repository files navigation

FreeCodeCamp File Metadata Microservice

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.

Node.js Express JavaScript

🚀 Features

  • 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

🛠️ Technologies Used

  • Node.js: Runtime environment
  • Express.js: Web framework
  • Multer: Middleware for handling multipart/form-data
  • CORS: Cross-origin resource sharing
  • dotenv: Environment variable management

📦 Installation

  1. Clone the repository

    git clone https://github.com/aliammari1/freecodecamp-filemetadata-project.git
    cd freecodecamp-filemetadata-project
  2. Install dependencies

    npm install
  3. Set up environment variables

    cp sample.env .env
    # Edit .env with your configuration
  4. Start the server

    npm start
  5. Open your browser

    Navigate to http://localhost:3000
    

🎯 Usage

API Endpoints

Upload File

  • POST /api/fileanalyse
  • Content-Type: multipart/form-data
  • Form field: upfile

Example Response:

{
  "name": "example.txt",
  "type": "text/plain",
  "size": 1024
}

Get Last Uploaded File Info

  • GET /api/fileanalyse

Example Response:

{
  "name": "example.txt",
  "type": "text/plain",
  "size": 1024
}

Using the Web Interface

  1. Navigate to the main page
  2. Select a file using the file input
  3. Click "Upload" to analyze the file
  4. View the metadata response

Using cURL

# 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

📁 Project Structure

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

🔧 Configuration

The application uses the following environment variables:

  • PORT: Server port (default: 3000)

🧪 Testing

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

🔍 API Response Format

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
}

🚀 Deployment

Local Development

npm start

Production Deployment

  1. Set environment variables
  2. Install production dependencies: npm ci --only=production
  3. Start the application: npm start

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Commit your changes: git commit -am 'Add feature'
  4. Push to the branch: git push origin feature-name
  5. Submit a pull request

📚 Learning Resources

This project is part of the FreeCodeCamp curriculum:

🏷️ Tags

nodejs express multer file-upload microservice freecodecamp backend api javascript

👨‍💻 Author

Ali Ammari


⭐ Star this repository if you found it helpful!

About

File metadata microservice developed with Node.js and Express for uploading files and retrieving essential metadata such as file name, type, and size in real-time.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •