DirectorySync: Multi-Directional FileSystem Synchronization
Synchronize directories between multiple machines over network with the ability to be synchronized in real-time.
Installation
DirectorySync requires Node.js version 14+ and can be installed using Node Package Manager (npm).
npm i directory-sync
Example: How To Setup A Server?
Below is a simple snippet for setting up a server and hosting directories which can then be mirrored on remote machines.
import { Server } from 'directory-sync';
const server = new Server({
port: 8080,
auth: 'some-secret-key'
});
server.on('log', (code, message) => console.log(`[SERVER][${code}] ${message}`));
server.on('error', (error) => console.log(`[SERVER]`, error));
server.host('my-directory-1', './path/to/some-directory');
server.host('my-directory-2', './path/to/some-directory-2', {
filters: {
keep: {
files: ['configuration.json'],
extensions: ['.html', '.css', '.js']
},
ignore: {
directories: ['node_modules']
}
}
});
Example: How To Setup Mirrors?
Below is a simple snippet for setting up a mirror and synchronizing a remote directory from the example above.
import { Mirror } from 'directory-sync';
const my_directory_2_mirror = new Mirror('my-directory-2', {
path: './mirrored-some-directory-2',
hostname: '127.0.0.1',
port: 8080,
auth: 'some-secret-key',
});
my_directory_2_mirror.on('log', (code, message) => console.log(`[MIRROR][${code}] ${message}`));
my_directory_2_mirror.on('error', (error) => console.log(`[MIRROR]`, error));