File System Over WebSocket — Access Node.js fs functions remotely via WebSocket. Designed specifically for ElectronJS architectures.
npm install fsovwsThe server exposes the fs.promises methods on a dedicated port.
const { startFSServer } = require('fsovws');
const fs = require('fs');
// SSL options for HTTPS
const sslOptions = {
cert: fs.readFileSync('path/to/cert.pem'),
key: fs.readFileSync('path/to/key.pem')
};
// Start the secure server on port 3000
startFSServer(3000, sslOptions);const { startUnsecureFSServer } = require('fsovws');
// Start the unsecure server on port 3000
startUnsecureFSServer(3000);The client creates a Proxy object that maps calls to the server.
const { connectToFS } = require('fsovws');
const fs = connectToFS('wss://localhost:3000');
async function run() {
// Create a file remotely
await fs.writeFile('remote.txt', 'Hello from fsovws');
// Read a remote file
const data = await fs.readFile('remote.txt', 'utf-8');
console.log(data);
// List directory contents
const files = await fs.readdir('.');
console.log(files);
// Get file stats
const stats = await fs.stat('remote.txt');
console.log(stats);
}
run();const { connectToUnsecureFS } = require('fsovws');
const fs = connectToUnsecureFS('ws://localhost:3000');
// Same usage as above- Native API: Uses the same syntax as
require('fs').promises. - Binary Support: Automatic conversion of
Bufferobjects for transfer. - Asynchronous: Fully based on
Promises(async/await). - Lightweight: Minimal dependency (
ws).
To publish this package to npm:
-
Ensure you have an npm account and are logged in:
npm login
-
Navigate to the package directory:
cd fsows -
Update the version in
package.jsonif necessary. -
Publish the package:
npm publish
Note: For secure publishing, consider using npm's two-factor authentication.
This project is licensed under the MIT license.
Made by gilay04 — https://geoloup.com/