Skip to content

File System Explorer API A simple API built with Node.js to explore file systems. It allows users to view directories and files and download files through a clean and straightforward RESTful interface.

Notifications You must be signed in to change notification settings

mahm0udnasr/File-System-Explorer-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

File System Explorer API

A Node.js server that provides an API for exploring and downloading system files and directories.

Prerequisites

  • Node.js (version 14 or later)
  • npm (Node.js package manager)

Installation

  1. Install required dependencies:
npm install
  1. Start the server:
node server.js

The server will run on port 3000: http://localhost:3000

API Endpoints

1. List Available Drives

GET /files

Returns a list of all available drives in the system with their details.

Response

{
    "isDrivesList": true,
    "drives": [
        {
            "mounted": "C:",
            "filesystem": "NTFS",
            "size": 256060514304,
            "used": 186504359936,
            "available": 69556154368,
            "capacity": "73%",
            "path": "C:\\"
        }
    ]
}

2. List Directory Contents

GET /files?path={directoryPath}

Returns the contents of the specified directory.

Parameters

  • path (query): Full path to the directory (e.g., C:\Users)

Response

{
    "isDrivesList": false,
    "currentPath": "C:\\Users",
    "contents": [
        {
            "name": "Documents",
            "path": "C:\\Users\\Documents",
            "isDirectory": true,
            "size": 4096,
            "created": "2024-01-01T00:00:00.000Z",
            "modified": "2024-01-01T00:00:00.000Z",
            "downloadUrl": null
        },
        {
            "name": "example.txt",
            "path": "C:\\Users\\example.txt",
            "isDirectory": false,
            "size": 1024,
            "created": "2024-01-01T00:00:00.000Z",
            "modified": "2024-01-01T00:00:00.000Z",
            "downloadUrl": "/download?path=C%3A%5CUsers%5Cexample.txt"
        }
    ]
}

3. Download File

GET /download?path={filePath}

Downloads the specified file.

Parameters

  • path (query): Full path to the file to download

Response

  • Success: File download starts
  • Error: JSON error message
{
    "error": "Error message here"
}

Quick Start Guide

  1. View Available Drives

    GET http://localhost:3000/files
    

    Lists all available drives in your system.

  2. Browse Directory

    GET http://localhost:3000/files?path=C:\Users
    

    Shows contents of the specified directory.

  3. Download File

    GET http://localhost:3000/download?path=C:\Users\example.txt
    

    Downloads the specified file.

Error Handling

The API returns appropriate HTTP status codes:

  • 200: Success
  • 400: Bad Request (invalid parameters)
  • 404: Not Found (file/directory doesn't exist)
  • 500: Internal Server Error

Error responses include a JSON object with error details:

{
    "error": "Error message",
    "details": "Additional error details"
}

Security Notes

  1. Access Control

    • The server has access to system files
    • Implement authentication if used in production
    • Restrict access to sensitive directories
  2. File Access

    • Some files/directories might be inaccessible due to permissions
    • System files (containing '$' in name) are filtered out
    • Directory traversal is prevented

Development

Built with:

  • Express.js - Web framework
  • node-disk-info - Drive information
  • cors - Cross-origin resource sharing

About

File System Explorer API A simple API built with Node.js to explore file systems. It allows users to view directories and files and download files through a clean and straightforward RESTful interface.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published