{"id":12657,"library":"webdav-server","title":"WebDAV Server for Node.js","description":"webdav-server is a robust and highly configurable WebDAV server implementation for Node.js, currently stable at version 2.6.2. It allows developers to create a WebDAV endpoint capable of serving various types of resources, including physical files and folders from a hard drive, in-memory virtual resources, dynamically processed/computed content, and entirely custom resource types, all within a single server instance. The project maintains an active release cadence with frequent updates, as seen with multiple patch and minor releases since its major version 2.0.0. Key differentiators include its flexible architecture that supports custom user managers, resource types, HTTP methods, and server state persistence, making it suitable for diverse applications from human-readable content management via WebDAV clients to inter-program information sharing with temporary file systems. It adheres strictly to RFC4918.","status":"active","version":"2.6.2","language":"javascript","source_language":"en","source_url":"https://github.com/OpenMarshal/npm-WebDAV-Server","tags":["javascript","webdav-server","webdav","server","virtual","typescript"],"install":[{"cmd":"npm install webdav-server","lang":"bash","label":"npm"},{"cmd":"yarn add webdav-server","lang":"bash","label":"yarn"},{"cmd":"pnpm add webdav-server","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Primary class for creating a WebDAV server instance. While CommonJS `require` might still work, `import` is the idiomatic way, especially with TypeScript and modern Node.js development.","wrong":"const WebDAVServer = require('webdav-server')","symbol":"WebDAVServer","correct":"import { WebDAVServer } from 'webdav-server'"},{"note":"Used to mount a file system directly from a physical path on the disk. Ensure correct path resolution and permissions for the specified root directory.","wrong":"import PhysicalFileSystem from 'webdav-server/lib/manager/PhysicalFileSystem'","symbol":"PhysicalFileSystem","correct":"import { PhysicalFileSystem } from 'webdav-server'"},{"note":"Provides an in-memory file system for temporary or programmatic resource management, ideal for testing or ephemeral data without disk persistence.","wrong":"import * as VFS from 'webdav-server/virtual'","symbol":"VirtualFileSystem","correct":"import { VirtualFileSystem } from 'webdav-server'"},{"note":"TypeScript type for configuring the WebDAV server. Use it to define server port, authentication, debug mode, and other settings.","symbol":"WebDAVServerOptions","correct":"import { WebDAVServerOptions } from 'webdav-server'"}],"quickstart":{"code":"import { WebDAVServer, PhysicalFileSystem } from 'webdav-server';\nimport * as http from 'http';\nimport * as path from 'path';\n\n// Define the port for the WebDAV server\nconst port = 8080;\n// Define the root directory for the physical file system\n// For a production environment, use a robust path resolution method\nconst physicalRootPath = path.resolve(__dirname, 'webdav-root');\n\n// Create a new WebDAV server instance\nconst server = new WebDAVServer({\n  port: port,\n  // debug: true, // Uncomment for detailed logging\n  // Set the server name and version for HTTP headers\n  serverName: 'My WebDAV Server',\n  version: '1.0.0'\n});\n\n// Configure a physical file system at the root '/physical' of the WebDAV server\n// This maps the physicalRootPath to the WebDAV path.\nserver.setFileSystem('/physical', new PhysicalFileSystem(physicalRootPath));\n\n// Alternatively, for a virtual file system:\n// server.setFileSystem('/virtual', new VirtualFileSystem());\n\n// Start the HTTP server to listen for WebDAV requests\nserver.start((s: http.Server) => {\n  console.log(`WebDAV server is listening on http://localhost:${port}`);\n  console.log(`Serving physical files from: ${physicalRootPath}`);\n  console.log('You can now connect with a WebDAV client (e.g., Cyberduck, Windows Network Drive).');\n  console.log('Example: Connect to http://localhost:8080/physical');\n});\n\n// Graceful shutdown\nprocess.on('SIGINT', () => {\n  console.log('\\nStopping WebDAV server...');\n  server.stop(() => {\n    console.log('WebDAV server stopped.');\n    process.exit(0);\n  });\n});","lang":"typescript","description":"This quickstart demonstrates how to set up a basic WebDAV server with a physical file system mounted at `/physical`, listening on port 8080, and includes graceful shutdown."},"warnings":[{"fix":"Review the official changelog and examples for version 2.x to adapt your codebase. Pay close attention to how request bodies are accessed and how custom properties are managed.","message":"Version 2.0.0 introduced significant internal changes and API modifications. Specifically, the `RequestContext` class properties and how `PROPPATCH` attributes are handled were updated, potentially breaking existing implementations that relied on version 1.x APIs.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Implement custom user managers and authentication/authorization middleware using `server.beforeRequest` or `server.afterRequest` hooks. Carefully validate paths and permissions for all operations on physical resources.","message":"Deploying a `WebDAVServer` with `PhysicalFileSystem` without implementing custom authentication, authorization, or robust path validation can expose your server to unauthorized access and potential data breaches.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Always provide an absolute path to `PhysicalFileSystem`, ideally resolved using `path.resolve(__dirname, 'your_data_folder')` to ensure consistency and prevent directory traversal vulnerabilities.","message":"The `PhysicalFileSystem` constructor takes a root path. Using relative paths (e.g., `'.'`) can lead to unexpected behavior depending on the process's current working directory. Misconfigured paths can also lead to unintended directory exposure.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Implement an authentication manager using `server.setUserManager()` and apply authorization logic within your custom resource definitions or through middleware hooks provided by the server.","message":"The default configuration of `webdav-server` does not include any authentication or authorization mechanisms. Without these, anyone can access and modify resources on your WebDAV server.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If encountering client compatibility issues, try adjusting the `strictMode` option or reviewing its impact on specific WebDAV methods. Consult client documentation for expected server behavior.","message":"The `strictMode` option (introduced in v1.6.0) can affect client compatibility. While offering flexibility, deviating from strict RFC4918 compliance might cause issues with some WebDAV clients.","severity":"deprecated","affected_versions":">=1.6.0"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Change the `port` option when creating your `WebDAVServer` instance to an available port (e.g., 8081), or identify and terminate the process currently using the desired port.","cause":"The network port configured for the WebDAV server (e.g., 8080) is currently occupied by another application or a previous server instance that was not properly shut down.","error":"Error: listen EADDRINUSE: address already in use :::8080"},{"fix":"Ensure that the root path provided to `new PhysicalFileSystem()` is always a valid, absolute string. Use `path.resolve(__dirname, 'your-webdav-root')` to guarantee an absolute path.","cause":"The `PhysicalFileSystem` was initialized with an `undefined` or non-string path, typically due to an unhandled variable or incorrect path resolution logic.","error":"TypeError: Path must be a string. Received undefined (at ... PhysicalFileSystem.constructor)"},{"fix":"Verify that your `UserManager` and `PrivilegeManager` (if implemented) grant the necessary permissions. Ensure the target resource correctly implements the desired WebDAV methods. Check if the client is expecting a file when it's a folder, or vice-versa.","cause":"A WebDAV client is attempting an operation (e.g., PROPFIND, PUT, DELETE) that is not permitted for the requested resource or due to the server's access control configuration. This often indicates a missing privilege, incorrect resource type, or misconfigured method support.","error":"HTTP/1.1 405 Method Not Allowed (from client side)"}],"ecosystem":"npm"}