nafs
TypeScript icon, indicating that this package has built-in type declarations

0.0.11 • Public • Published

Node Active FS - nafs

npm install nafs
yarn add nafs

Example

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

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

Package Sidebar

Install

npm i nafs

Weekly Downloads

1

Version

0.0.11

License

MIT

Unpacked Size

23.6 kB

Total Files

13

Last publish

Collaborators

  • ricsam