Skip to content
/ nafs Public

Node Active FS - nafs. File system abstraction to read/write files to AWS S3 or local directory. Includes middleware for usage with express.

License

Notifications You must be signed in to change notification settings

ricsam/nafs

Repository files navigation

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

About

Node Active FS - nafs. File system abstraction to read/write files to AWS S3 or local directory. Includes middleware for usage with express.

Resources

License

Stars

Watchers

Forks

Packages

No packages published