{"id":17404,"library":"webdav-client","title":"WebDAV Client for Node.js","description":"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.","status":"active","version":"1.4.3","language":"javascript","source_language":"en","source_url":"https://github.com/OpenMarshal/npm-WebDAV-Client","tags":["javascript","webdav-client","webdav","client","typescript"],"install":[{"cmd":"npm install webdav-client","lang":"bash","label":"npm"},{"cmd":"yarn add webdav-client","lang":"bash","label":"yarn"},{"cmd":"pnpm add webdav-client","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Standard namespace import for accessing all exports, where `Connection` is a property of `webdavClient`.","wrong":"import webdavClient from 'webdav-client'","symbol":"* as webdavClient","correct":"import * as webdavClient from 'webdav-client'"},{"note":"Named import for direct access to the primary `Connection` class.","wrong":"import Connection from 'webdav-client'","symbol":"Connection","correct":"import { Connection } from 'webdav-client'"},{"note":"CommonJS import pattern. The `Connection` class is a property of the module object exported by `webdav-client`. Direct destructuring like `const { Connection } = require('webdav-client')` might not always yield the expected class if the module's export structure changes.","wrong":"const { Connection } = require('webdav-client');","symbol":"Connection (CommonJS)","correct":"const webdavClient = require('webdav-client');\nconst connection = new webdavClient.Connection(...);"}],"quickstart":{"code":"import { Connection } from 'webdav-client';\nimport * as path from 'path';\n\nconst webdavUrl = process.env.WEBDAV_URL ?? 'http://localhost:1900';\nconst webdavUser = process.env.WEBDAV_USER;\nconst webdavPass = process.env.WEBDAV_PASS;\n\nconst options = { url: webdavUrl };\nif (webdavUser && webdavPass) {\n    options.username = webdavUser;\n    options.password = webdavPass;\n}\n\nconst connection = new Connection(options);\nconst filePath = '/path/of/my/file.txt';\n\nconsole.log(`Attempting to fetch file '${filePath}' from ${webdavUrl}`);\n\nconnection.get(filePath, (e, content) => {\n    if (e) {\n        console.error(`Error fetching file: ${e.message}`);\n        // Additional error handling based on status codes (e.g., 404, 401)\n        if (e.statusCode === 404) {\n            console.error('File not found.');\n        } else if (e.statusCode === 401) {\n            console.error('Unauthorized access. Check credentials.');\n        }\n        return;\n    }\n    \n    console.log(`Content of '${filePath}':\\n${content.toString()}`);\n});\n","lang":"typescript","description":"Demonstrates how to initialize the WebDAV client with optional authentication and fetch the content of a specified file using its callback-based API."},"warnings":[{"fix":"For frontend applications, use a WebDAV client library specifically built and tested for browser compatibility.","message":"The `webdav-client` library is explicitly designed for Node.js environments and is not intended for use in browsers.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Wrap callback-based methods in Promises using `util.promisify` from Node.js's built-in `util` module to enable `async/await` syntax, or choose an alternative client that natively supports Promises.","message":"The API exclusively uses a callback-based asynchronous pattern, which might require adaptation if your project primarily uses Promises or async/await.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Implement custom retry logic around API calls (e.g., using libraries like `p-retry` for Promises or a custom loop for callbacks) to improve resilience against intermittent connection issues.","message":"The library does not include built-in retry mechanisms for transient network failures or server unavailability.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-22T00:00:00.000Z","next_check":"2026-07-21T00:00:00.000Z","problems":[{"fix":"Verify that the WebDAV server is operational and reachable from the client's host. Ensure the `url` provided in the `Connection` constructor is correct.","cause":"The WebDAV server is not running, is inaccessible, or the specified URL/port is incorrect.","error":"connect ECONNREFUSED <IP>:<PORT>"},{"fix":"Double-check the path provided to WebDAV methods (e.g., `get`, `readdir`, `put`) for accuracy against the server's directory structure.","cause":"The requested file or directory does not exist on the WebDAV server at the specified path.","error":"Error: Not Found (404)"},{"fix":"Provide valid `username` and `password` in the `ConnectionOptions` or ensure a custom `authenticator` is correctly configured.","cause":"The client failed to authenticate with the WebDAV server due to incorrect or missing credentials.","error":"Error: Unauthorized (401)"}],"ecosystem":"npm","meta_description":null}