π File Reader API
A simple Node API that reads a file from the serverβs filesystem and returns its contents as a response. Useful for learning how to handle file I/O in Node.js and exposing data through REST endpoints.
π Features
- β **Read File * β `/api/data' returns the contents of a specified file.
- β Easy to Extend β Add support for multiple files, file uploads, or streaming.
π Project Structure
file_reader/ βββ app.js # Main server file βββ data/sample.txt # Example file to read βββ README.md # Documentation
`
βοΈ Installation
git clone:
cd file_reader
`
βΆοΈ Running the Server
node app.js
Youβll see:
Server running on port 3000
π API Usage
GET `/api/data`
Returns the contents of `sample.txt` (or any configured file).
*Example:*
http://localhost:3000/api/data
*Response:*
Hello, this is the content of sample.txt
β οΈ Error Responses
- *404 Not Found* β File does not exist.
- *500 Internal Server Error* β Could not read file.
π To-Do (Optional Enhancements)
- [ ] Add support for reading multiple files via `/file/:filename`.
- [ ] Add file upload endpoint.
- [ ] Stream large files instead of loading into memory.
- [ ] Add authentication for sensitive files.
π License
MIT β free to use and modify.
πββοΈ Author
*Dimond Madechawo*
https://github.com/dimondkudzai