Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/reekoheek/node-bono-file
https://github.com/reekoheek/node-bono-file
Last synced: 3 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/reekoheek/node-bono-file
- Owner: reekoheek
- License: mit
- Created: 2018-04-04T02:04:18.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-23T20:38:38.000Z (almost 2 years ago)
- Last Synced: 2024-04-27T01:40:56.967Z (7 months ago)
- Language: JavaScript
- Size: 612 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-xinix - bono-file - Bono file server - [reekoheek](https://github.com/reekoheek) (Grouping / Node)
README
# bono-file
```sh
npm i bono-file
```Bono file server
## Create server
```js
const http = require('http');
const { FileBundle } = require('bono-file');const PORT = process.env.PORT || 3000;
const bundle = new FileBundle({ dataDir: '/path/to/data/dir' });
const server = http.createServer(bundle.callback());server.listen(PORT, () => console.info('Listening at', PORT));
```## Upload
```html
```
## Get file
```js
let file = 'change this to filename';await fetch(`/files/foo/${file}`); // get as mimetype
await fetch(`/files/foo/${file}?attachment=1`); // download with default name
await fetch(`/files/foo/${file}?attachment=1&name=foo.txt`); // download with specified name
```## Use middlewares
```js
const http = require('http');
const Bundle = require('bono');const { FileSystem, upload, download } = require('bono-file');
const PORT = process.env.PORT || 3000;
const fs = new FileSystem({ dataDir: '/path/to/data/dir' });
const bundle = new Bundle();
bundle.use(upload({ fs }));
bundle.use(download({ fs }));const server = http.createServer(bundle.callback());
server.listen(PORT, () => console.info('Listening at', PORT));
```