htfs

0.0.3 • Public • Published

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 💖

Readme

Keywords

none

Package Sidebar

Install

npm i htfs

Weekly Downloads

7

Version

0.0.3

License

MIT

Unpacked Size

6.57 kB

Total Files

6

Last publish

Collaborators

  • pi0