Registry / http-networking / webdav

webdav

JSON →
library1.1.7jsnpmunverified

The `webdav` library provides a promise-based WebDAV client for interacting with remote filesystems, supporting both Node.js and browser environments. Currently at version 5.9.0, the library is under active development, with version 4 in maintenance mode until January 2025, and earlier versions deprecated. It differentiates itself by prioritizing an easy-to-consume client API for common WebDAV services (like Nextcloud, ownCloud, Box, Yandex) over strict RFC adherence. Version 5 transitioned to ECMAScript Modules (ESM) and uses `@buttercup/fetch` for requests, replacing Axios from prior versions. This enables cross-platform compatibility, leveraging native `fetch` in browsers and `node-fetch` in Node.js, making it suitable for modern JavaScript projects.

npm install webdav
INSTALL
IMPORT
SIG · WEBDAV
W
webdav
http-networkingjavascriptv1.1.7
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

createClient
✓ import { createClient } from 'webdav';
✗ const { createClient } = require('webdav');
ESM-only since v5. The CommonJS `require` syntax will result in `ERR_REQUIRE_ESM`.
WebDAVClient
✓ import { WebDAVClient } from 'webdav';
✗ import WebDAVClient from 'webdav';
The `WebDAVClient` class is a named export, not a default export.
createClient (web entrypoint)
✓ import { createClient } from 'webdav/web';
✗ import { createClient } from 'webdav'; // for older browser environments that need an explicit web entrypoint
In v5, `import { createClient } from 'webdav'` works for most modern bundlers for both Node and browser. This explicit `/web` entry point was more critical in v4 and earlier for browser usage, but is still available.
FileStat (type)
✓ import type { FileStat } from 'webdav';
Used for type-checking when working with file and directory statistics returned by methods like `getDirectoryContents`.

This quickstart demonstrates how to initialize a WebDAV client, list directory contents, create a directory, upload a file, download it, and finally clean up the created resources.

import { createClient, FileStat } from 'webdav'; import * as fs from 'fs/promises'; // For Node.js file system operations import path from 'path'; // Configure your WebDAV client const webdavUrl = process.env.WEBDAV_URL ?? 'https://example.com/webdav/'; const username = process.env.WEBDAV_USERNAME ?? 'your-username'; const password = process.env.WEBDAV_PASSWORD ?? 'your-password'; const client = createClient(webdavUrl, { username, password }); async function runWebDAVOperations() { try { console.log(`Connecting to WebDAV at: ${webdavUrl}`); // 1. List contents of the root directory const contents: FileStat[] = await client.getDirectoryContents('/'); console.log('Root directory contents:'); contents.forEach(item => { console.log(`- ${item.type === 'directory' ? 'Dir' : 'File'}: ${item.filename} (size: ${item.size ?? 'N/A'} bytes)`); }); // 2. Create a new directory const newDirPath = '/test-directory'; await client.createDirectory(newDirPath); console.log(`Directory created: ${newDirPath}`); // 3. Upload a file const localFilePath = path.join(__dirname, 'test-upload.txt'); await fs.writeFile(localFilePath, 'Hello, WebDAV from checklist.day!'); const remoteFilePath = `${newDirPath}/uploaded-file.txt`; await client.putFileContents(remoteFilePath, await fs.readFile(localFilePath)); console.log(`File uploaded: ${remoteFilePath}`); // 4. Download the file and verify content const downloadedContent = await client.getFileContents(remoteFilePath, { format: 'text' }); console.log(`Downloaded content from ${remoteFilePath}: "${downloadedContent}"`); // 5. Delete the uploaded file and directory await client.deleteFile(remoteFilePath); console.log(`File deleted: ${remoteFilePath}`); await client.deleteFile(newDirPath); // Can delete directories too console.log(`Directory deleted: ${newDirPath}`); // Clean up local test file await fs.unlink(localFilePath); } catch (error) { console.error('WebDAV operation failed:', error); } } runWebDAVOperations();
Debug
Known issues
breakingVersion 5.x of the `webdav` library is ESM-only. CommonJS `require()` is no longer supported, requiring projects to adopt ES Modules syntax and configuration.
fix
Migrate your project to use ES Modules (e.g., add `'type': 'module'` to `package.json` and use `import` statements) or use an earlier `webdav` version (4.x or below) which supports CommonJS.
affects: >=5.0.0
breakingThe underlying HTTP request library changed from Axios to `@buttercup/fetch` (which uses `node-fetch` in Node.js) in version 5.x. Direct reliance on Axios APIs or its error structure will no longer work.
fix
Update any code that directly interacted with Axios-specific features or expected Axios-shaped error objects. Ensure your environment correctly handles `fetch` API polyfills if necessary, though `@buttercup/fetch` abstracts much of this.
affects: >=5.0.0
deprecatedSupport for version 4.x of the `webdav` library will be dropped in January 2025. This means no further security or stability bugfixes will be provided for v4.
fix
Migrate to version 5.x as soon as possible to receive ongoing updates and security fixes. Review the breaking changes for v5 before migrating.
affects: <5.0.0
gotchaWhile Node.js 14+ is officially supported for `webdav` v5, active testing only occurs on Node.js 18 and newer. Issues encountered on older Node.js versions may require community support for resolution.
fix
For optimal stability, performance, and support, use `webdav` v5 with Node.js 18 or newer. If using older Node.js versions, be prepared for potential compatibility issues and ensure thorough testing.
affects: >=5.0.0
gotchaBrowser environments using `webdav` v5 require an ESM-compatible bundler (e.g., Webpack, Rollup) as UMD module format support was removed. Loading via a `<script>` tag is no longer directly supported for browser builds.
fix
Configure your project's bundler to correctly handle ESM modules. The explicit `/web` entry point is still available but often not required with modern bundlers.
affects: >=5.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM
Attempting to `require()` the `webdav` package in a CommonJS environment when using version 5 or higher.
fix
Change `require('webdav')` to `import { ... } from 'webdav';` and ensure your `package.json` has `'type': 'module'`, or downgrade to `webdav` version 4.x.
TypeError: client.getDirectoryContents is not a function
Incorrect import of `createClient` or `WebDAVClient`, often due to mixing default/named imports or CJS/ESM patterns.
fix
Ensure you are using `import { createClient } from 'webdav';` for named exports, and avoid `import createClient from 'webdav';` unless the library explicitly exports a default. Check for correct module resolution in your build configuration.
Error: fetch failed (in Node.js) or TypeError: fetch is not a function (in older Node.js/browser environments)
Potential issues with `node-fetch` resolution by `@buttercup/fetch` in Node.js, or `fetch` not being globally available or correctly polyfilled in certain environments.
fix
Verify Node.js version compatibility (>=14 for v5). If in a custom environment or older browser, ensure `global.fetch` is correctly polyfilled. `@buttercup/fetch` should handle `node-fetch` transparently in supported Node.js versions.
405 Method Not Allowed
The WebDAV server does not support the HTTP method being used (e.g., PUT, DELETE, MKCOL) for the requested resource or path, often due to server configuration or permissions.
fix
Check the WebDAV server's configuration and permissions for the affected path. Some servers are read-only or restrict certain operations. Ensure your client's authentication details are correct.
Upgrade
Version history
1.1.7latest on npm
Audit
Dependencies
@buttercup/fetchrequiredHandles cross-platform HTTP requests, abstracting `fetch` API differences between browser and Node.js environments. Uses `node-fetch` in Node.js.
Agent activity
41 hits · last 30 days
node
35
OpenAI (training)
1
Resources
webdav — npm install webdav · libregistry