Rsync CLI Wrapper

0.6.1 · active · verified Wed Apr 22

node-rsync is a Node.js library that provides a programmatic interface for building and executing `rsync` commands. It functions as a wrapper around the system's `rsync` utility, allowing developers to construct complex synchronization commands using a fluent API in JavaScript or TypeScript applications. The current stable version is 0.6.1. Releases are infrequent, typically addressing specific bugs or adding minor enhancements (such as Windows path support), rather than following a strict cadence. Its primary utility lies in automating file synchronization, backup tasks, and deployments within Node.js environments by abstracting the command-line intricacies of `rsync` into a more manageable, object-oriented structure.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize an Rsync instance, configure a basic remote synchronization command using SSH, common flags (archive, compress), and then execute it with error handling.

const Rsync = require('rsync');

// 1. Build the rsync command configuration
const rsync = new Rsync()
  .shell('ssh')                 // Use SSH for remote connections
  .flags('az')                 // 'a' for archive mode, 'z' for compress
  .source('/path/to/local/source/') // Local directory to synchronize from
  .destination('user@remote.server:/path/to/remote/destination/'); // Remote destination

// 2. Execute the command and handle results
rsync.execute(function(error, code, cmd) {
    if (error) {
        console.error('Rsync command failed:', error.message);
        console.error('Exit Code:', code);
        console.error('Executed Command:', cmd);
        // Depending on `code`, you might want to retry or log specific errors
    } else {
        console.log('Rsync command completed successfully.');
        console.log('Executed Command:', cmd);
        // Further processing after successful synchronization
    }
});

view raw JSON →