Expose filesystem via HTTP and access it from the other side!
This module works best with memory-fs.
Install package:
yarn add htfs
OR
npm install htfs
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/
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)
})
Required. HTTP URL of server.
MIT. Made with 💖