@jun-a/local-filebrowser
Simple local file browser web application with CLI support. Browse your files and preview content in a web interface.
Installation
Global Installation (Recommended)
npm install -g @jun-a/local-filebrowser
Local Installation
npm install @jun-a/local-filebrowser
Usage
CLI Commands
After global installation, you can use either command:
Short command (lfb
):
lfb
lfb -p 8080
lfb -d ~/Documents
lfb -p 8080 -d ~/Downloads
Full command (local-file-browser
):
local-file-browser
local-file-browser -p 8080
local-file-browser -d ~/Documents
local-file-browser -p 8080 -d ~/Downloads
CLI Options
-p, --port <number>
: Port number (default: 3099)
-d, --path <path>
: Directory path to browse (default: current directory)
-h, --help
: Show help message
-v, --version
: Show version number
Programmatic Usage
const path = require('path');
const { spawn } = require('child_process');
process.env.PORT = '8080';
process.env.DATA_PATH = path.resolve('./my-directory');
require('@jun-a/local-filebrowser');
Manual Installation
git clone <repository-url>
cd local-filebrowser
npm install
npm start
Features
- Directory browsing: View files and folders in any directory
- File preview: Support for multiple file types
- Markdown (.md): Rendered HTML display
- Code files (.js, .css, .html, .py, .java, .cpp, etc.): Syntax highlighting
- Text files (.txt): Plain text display
- Images (.png, .jpg, .gif, etc.): Image display
- Breadcrumb navigation: Easy navigation through directory hierarchy
- Responsive design: Mobile-friendly interface
- Security: Path traversal protection and file size limits
Environment Variables
PORT
: Server port (default: 3099)
DATA_PATH
: Base directory path (default: current working directory)
Web Interface
- Open your browser and go to
http://localhost:3099
(or your specified port)
- Enter a directory path in the input field
- Click "Browse" or press Enter
- Click on files to preview them
- Click on folders to navigate into them
API Endpoints
GET /api/browse
- Parameter:
path
(directory path)
- Response: List of files and folders
GET /api/preview
- Parameter:
path
(file path)
- Response: File content and type information
GET /api/file
- Parameter:
path
(file path)
- Response: Raw file data
Security Features
- File size limit (1MB for preview)
- Path traversal protection
- Proper MIME type handling
- Error handling and validation
Technology Stack
- Frontend: HTML5, CSS3, JavaScript (ES6+)
- Backend: Node.js, Express.js
- Markdown processing: marked.js
- Syntax highlighting: highlight.js
- MIME type handling: mime-types
File Structure
@jun-a/local-filebrowser/
├── bin/
│ └── lfb.js # CLI executable
├── public/
│ ├── css/
│ │ └── styles.css
│ └── js/
│ └── app.js
├── views/
│ └── index.html
├── server.js # Main server file
├── package.json
└── README.md
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
ISC License
Changelog
v1.0.0
- Initial release
- CLI support with
lfb
command
- File browsing and preview functionality
- Responsive web interface