Skip to content

Latest commit

 

History

History
103 lines (69 loc) · 2.38 KB

README.md

File metadata and controls

103 lines (69 loc) · 2.38 KB

HTTP Filesystem

npm version npm downloads package phobia

Standard JS david dm codecov circleci

Expose filesystem via HTTP and access it from the other side!

This module works best with memory-fs.

Install

Install package:

yarn add htfs

OR

npm install htfs

Server

Serving real fs is not a good idea. In this example we serve a virtual filesystem.

const HTTPFSMiddleware = require('htfs/lib/middleware')
const express = require('express')
const MFS = require('memory-fs')

// Create a new express app listening on port 8080
const app = express()
app.listen(8080)

// Create a new Virtual FileSystem with a test file
const mfs = new MFS()
mfs.mkdirpSync('/test')
mfs.writeFileSync('/test/file.txt', 'Works!')

// Create and register fs middleware
app.use('/mfs', HTTPFSMiddleware(mfs))

You can now browse filesystem with broweser: http://localhost:8080/mfs/

Client

Supported methods:

  • exists(path): Promise<Boolean>
  • readFile(path): Promise<String>
const HTTPFSAClient = require('htfs/lib/client')

const fs = new HTTPFSAClient({
  endpoint: 'http://localhost:8080/mfs'
})

fs.readFile('/test/file.txt').then((contents) => {
  console.log('File contents:', contents)
})

Options

endpoint

Required. HTTP URL of server.

License

MIT. Made with 💖