Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

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.

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 */
```