https://github.com/catamphetamine/simple-http-file-server
A simple HTTP static file server
https://github.com/catamphetamine/simple-http-file-server
Last synced: 3 months ago
JSON representation
A simple HTTP static file server
- Host: GitHub
- URL: https://github.com/catamphetamine/simple-http-file-server
- Owner: catamphetamine
- Created: 2018-06-25T22:54:22.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-26T11:44:11.000Z (almost 7 years ago)
- Last Synced: 2025-01-11T01:48:16.425Z (5 months ago)
- Language: JavaScript
- Size: 36.1 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Simple HTTP server
## Use
```sh
$ npm install simple-http-file-server --save
```Running is easier via `npx`.
```
$ npm install npx --save
````npx` [doesn't currently work on Windows](https://github.com/zkat/npx/issues/144) so on Windows `npx file-server` can be substituted with `node node_modules/simple-http-file-server/bin/file-server`.
Running:
```sh
$ npx file-server
```Will serve files from current directory on port `8080`:
```sh
$ npx file-server . 8080
```Will serve files from current directory on port `8080`, and if the requested file is not found then it will serve `./index.html` from the root directory with HTTP Status `200`:
```sh
$ npx file-server . 8080 "{\"default\": \"./index.html\"}"
```Will serve files from current directory on port `8080`, and if the requested file is not found then it will serve `./404.html` from the root directory with HTTP Status `404`:
```sh
$ npx file-server . 8080 "{\"404\": \"./404.html\"}"
```## API
```js
import createServer from 'simple-http-file-server'createServer({
root: '/path/to/directory',
options: {
...
}
}).listen('8888', () => console.log('Static file server listening at http://localhost:8888'))
```