https://github.com/floor2/static-fileserver-middleware
Serve static files from any directory/mount point, Express-style middleware.
https://github.com/floor2/static-fileserver-middleware
express fileserver nodejs static
Last synced: 8 months ago
JSON representation
Serve static files from any directory/mount point, Express-style middleware.
- Host: GitHub
- URL: https://github.com/floor2/static-fileserver-middleware
- Owner: floor2
- Created: 2019-10-05T12:18:06.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2020-03-31T19:49:10.000Z (almost 6 years ago)
- Last Synced: 2025-02-18T01:42:49.980Z (11 months ago)
- Topics: express, fileserver, nodejs, static
- Language: JavaScript
- Size: 18.6 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Static Fileserver Middleware

Serve static files from any route and any folder, like a window into an underlying filesystem.
## Installation
```
yarn install static-fileserver-middleware
```
## Usage
Example app:
```
var static = require('static-fileserver-middleware');
var app = require('express')();
app.get('/', (r, res) => res.send('Files'));
app.use(static({ rootDir: './public' }));
app.listen(3000);
```
Example with different baseUrl:
```
var static = require('static-fileserver-middleware');
var app = require('express')();
var baseUrl = '/ok'
app.get('/', (r, res) => res.send('Files'));
app.use(baseUrl, static({ baseUrl, rootDir: './public' }));
app.listen(3000);
```
### Options
|Option|Type|
|-|-|
|baseUrl|`String`|
|rootDir|`String`|
# Justification
The reasoning for making a new library for this was because none of the other
ones worked when mounted not at the root.