Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ricsam/nafs
Node Active FS - nafs. File system abstraction to read/write files to AWS S3 or local directory. Includes middleware for usage with express.
https://github.com/ricsam/nafs
Last synced: 10 days ago
JSON representation
Node Active FS - nafs. File system abstraction to read/write files to AWS S3 or local directory. Includes middleware for usage with express.
- Host: GitHub
- URL: https://github.com/ricsam/nafs
- Owner: ricsam
- License: mit
- Created: 2020-03-07T11:04:16.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-07-12T04:39:37.000Z (over 1 year ago)
- Last Synced: 2024-04-16T10:10:02.817Z (7 months ago)
- Language: TypeScript
- Homepage:
- Size: 132 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Node Active FS - nafs
```
npm install nafs
yarn add nafs
```### Example
```js
const { nafs, expressMiddleware } = require('nafs');
const express = require('express');const localFs = nafs('file:///tmp/dev_storage');
const remoteFs = nafs('s3://key:secret@us-east-1/bucket_name/some/path');const app = express();
app.use('/local-files', expressMiddleware(localFs.createReadStream));
app.use('/remote-files', expressMiddleware(remoteFs.createReadStream));app.get('/', (req, res) => {
remoteFs.writeFile('/hello', 'Hello World').then(() => {
res.send('saved file to s3, check it out on /remote-files/hello or /read');
});
});
app.get('/read', (req, res) => {
removeFs.readFile('/hello').then((file) => {
res.send(file);
});
});
```### Enable cache for remote data
```js
const remoteFs = nafs('s3://key:secret@us-east-1/bucket_name?cacheDir=/tmp/images');console.time('hello');
await remoteFs.readFile('/hello')
console.timeEnd('hello'); /* 70 ms *//* now cached */
console.time('hello');
await remoteFs.readFile('/hello')
console.timeEnd('hello'); /* 2 ms */
```