A Node.js server that provides an API for exploring and downloading system files and directories.
- Node.js (version 14 or later)
- npm (Node.js package manager)
- Install required dependencies:
npm install
- Start the server:
node server.js
The server will run on port 3000: http://localhost:3000
GET /files
Returns a list of all available drives in the system with their details.
{
"isDrivesList": true,
"drives": [
{
"mounted": "C:",
"filesystem": "NTFS",
"size": 256060514304,
"used": 186504359936,
"available": 69556154368,
"capacity": "73%",
"path": "C:\\"
}
]
}
GET /files?path={directoryPath}
Returns the contents of the specified directory.
path
(query): Full path to the directory (e.g.,C:\Users
)
{
"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"
}
]
}
GET /download?path={filePath}
Downloads the specified file.
path
(query): Full path to the file to download
- Success: File download starts
- Error: JSON error message
{
"error": "Error message here"
}
-
View Available Drives
GET http://localhost:3000/files
Lists all available drives in your system.
-
Browse Directory
GET http://localhost:3000/files?path=C:\Users
Shows contents of the specified directory.
-
Download File
GET http://localhost:3000/download?path=C:\Users\example.txt
Downloads the specified file.
The API returns appropriate HTTP status codes:
200
: Success400
: 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"
}
-
Access Control
- The server has access to system files
- Implement authentication if used in production
- Restrict access to sensitive directories
-
File Access
- Some files/directories might be inaccessible due to permissions
- System files (containing '$' in name) are filtered out
- Directory traversal is prevented
Built with:
- Express.js - Web framework
- node-disk-info - Drive information
- cors - Cross-origin resource sharing