WebDAV Client for Node.js

1.4.3 · active · verified Wed Apr 22

webdav-client is a Node.js library offering a comprehensive, callback-based API for interacting with WebDAV servers. Currently stable at version 1.4.3, this package provides a suite of methods for common file and directory operations, including `get`, `put`, `readdir`, `mkdir`, `delete`, `move`, `copy`, alongside robust capabilities for property management (setting, removing, retrieving properties) and locking mechanisms. It also supports custom HTTP requests and stream-based data transfers for efficient handling of large files. The library is specifically designed for server-side Node.js environments and explicitly states it is not yet suitable for browser usage. Its primary differentiating factors include its direct, callback-centric programming model, which allows for fine-grained control over WebDAV protocol interactions, and its focus on Node.js compatibility. While a specific release cadence is not documented, the versioning suggests a mature and stable codebase for integrating WebDAV functionalities into Node.js applications.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to initialize the WebDAV client with optional authentication and fetch the content of a specified file using its callback-based API.

import { Connection } from 'webdav-client';
import * as path from 'path';

const webdavUrl = process.env.WEBDAV_URL ?? 'http://localhost:1900';
const webdavUser = process.env.WEBDAV_USER;
const webdavPass = process.env.WEBDAV_PASS;

const options = { url: webdavUrl };
if (webdavUser && webdavPass) {
    options.username = webdavUser;
    options.password = webdavPass;
}

const connection = new Connection(options);
const filePath = '/path/of/my/file.txt';

console.log(`Attempting to fetch file '${filePath}' from ${webdavUrl}`);

connection.get(filePath, (e, content) => {
    if (e) {
        console.error(`Error fetching file: ${e.message}`);
        // Additional error handling based on status codes (e.g., 404, 401)
        if (e.statusCode === 404) {
            console.error('File not found.');
        } else if (e.statusCode === 401) {
            console.error('Unauthorized access. Check credentials.');
        }
        return;
    }
    
    console.log(`Content of '${filePath}':\n${content.toString()}`);
});

view raw JSON →