@jun-a/local-filebrowser
v2.0.1
Published
Simple file browser web application built with Express.js
Maintainers
Readme
@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-filebrowserLocal Installation
npm install @jun-a/local-filebrowserUsage
CLI Commands
After global installation, you can use either command:
Short command (lfb):
# Start file browser on default port (3099)
lfb
# Start on specific port
lfb -p 8080
# Browse specific directory
lfb -d ~/Documents
# Combine options
lfb -p 8080 -d ~/DownloadsFull command (local-file-browser):
# Start file browser on default port (3099)
local-file-browser
# Start on specific port
local-file-browser -p 8080
# Browse specific directory
local-file-browser -d ~/Documents
# Combine options
local-file-browser -p 8080 -d ~/DownloadsCLI 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');
// Set environment variables
process.env.PORT = '8080';
process.env.DATA_PATH = path.resolve('./my-directory');
// Start server
require('@jun-a/local-filebrowser');Manual Installation
git clone <repository-url>
cd local-filebrowser
npm install
npm startFeatures
- 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.mdContributing
- 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
lfbcommand - File browsing and preview functionality
- Responsive web interface
