WebDAV Server for Node.js

2.6.2 · active · verified Sun Apr 19

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import { WebDAVServer, PhysicalFileSystem } from 'webdav-server';
import * as http from 'http';
import * as path from 'path';

// Define the port for the WebDAV server
const port = 8080;
// Define the root directory for the physical file system
// For a production environment, use a robust path resolution method
const physicalRootPath = path.resolve(__dirname, 'webdav-root');

// Create a new WebDAV server instance
const server = new WebDAVServer({
  port: port,
  // debug: true, // Uncomment for detailed logging
  // Set the server name and version for HTTP headers
  serverName: 'My WebDAV Server',
  version: '1.0.0'
});

// Configure a physical file system at the root '/physical' of the WebDAV server
// This maps the physicalRootPath to the WebDAV path.
server.setFileSystem('/physical', new PhysicalFileSystem(physicalRootPath));

// Alternatively, for a virtual file system:
// server.setFileSystem('/virtual', new VirtualFileSystem());

// Start the HTTP server to listen for WebDAV requests
server.start((s: http.Server) => {
  console.log(`WebDAV server is listening on http://localhost:${port}`);
  console.log(`Serving physical files from: ${physicalRootPath}`);
  console.log('You can now connect with a WebDAV client (e.g., Cyberduck, Windows Network Drive).');
  console.log('Example: Connect to http://localhost:8080/physical');
});

// Graceful shutdown
process.on('SIGINT', () => {
  console.log('\nStopping WebDAV server...');
  server.stop(() => {
    console.log('WebDAV server stopped.');
    process.exit(0);
  });
});

view raw JSON →