npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, πŸ‘‹, I’m Ryan HefnerΒ  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you πŸ™

Β© 2025 – Pkg Stats / Ryan Hefner

webdav-serve

v1.0.6

Published

Transform your local disk into a network drive with Node.js πŸš€πŸ“πŸŒ

Readme

WebDAV Serve πŸš€

A simple, customizable WebDAV server for sharing your local disk as a network drive. Built with Node.js for easy integration and modification.

Features ✨

  • Full WebDAV Protocol Support - PROPFIND, GET, PUT, DELETE, MOVE, MKCOL, LOCK/UNLOCK
  • Range Requests - Partial content support for large files
  • Session Management - Lock tokens with automatic cleanup
  • Easy Customization - Simple callback-based API

Quick Start πŸƒβ€β™‚οΈ

const webdav = require('webdav-serve');
const http = require('http');
const fs = require('fs');
const path = require('path');
const server = http.createServer();

function resolveDiskPath(rel) {
    const root = path.join(__dirname, 'files');  //ROOT_DIR
    if (!rel) return root;
    rel = rel.replace(/^\\+/g, '/');
    rel = rel.replace(/^\/+/, '');
    return path.join(root, rel);
}

if (!fs.existsSync(resolveDiskPath('/'))) {
    fs.mkdirSync(resolveDiskPath('/'));
}

server.listen(8080, () => {
    console.log('πŸš€ WebDAV server is running at http://localhost:8080');
});

webdav(server, {
    list: function (pathname) {
        const originalPath = pathname;
        const diskPath = resolveDiskPath(pathname);

        if (!fs.existsSync(diskPath)) return [];

        if (!fs.statSync(diskPath).isDirectory()) {
            return [{ name: originalPath, size: fs.statSync(diskPath).size, type: 'file', lastmod: fs.statSync(diskPath).mtime }];
        } else {
            const files = fs.readdirSync(diskPath);
            files.push(".");
            return files
                .filter(f => fs.existsSync(path.join(diskPath, f)))
                .map(f => {
                    const fullPath = path.join(diskPath, f);
                    const relativeName = path.posix.join(originalPath === '/' ? '/' : originalPath.replace(/\/$/, ''), f).replace(/\/+/g, '/');
                    return { name: relativeName, size: fs.statSync(fullPath).size, type: fs.statSync(fullPath).isDirectory() ? 'directory' : 'file', lastmod: fs.statSync(fullPath).mtime };
                });
        }
    },
    get: function (pathname, options = {}) {
        const diskPath = resolveDiskPath(pathname);
        if (!fs.existsSync(diskPath)) return null;

        const { start, end } = options;
        const streamOptions = {};

        if (start !== undefined) streamOptions.start = start;
        if (end !== undefined) streamOptions.end = end;

        const stream = fs.createReadStream(diskPath, streamOptions);

        stream.on('error', (err) => {
            console.error('Error reading file:', err);
        });
        return stream;
    },
    write: function (pathname, req) {
        return new Promise((resolve) => {
            const diskPath = resolveDiskPath(pathname);
            const dir = path.dirname(diskPath);
            if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
            const stream = fs.createWriteStream(diskPath);

            req.on('data', (chunk) => {
                stream.write(chunk);
            });

            req.on('end', () => {
                stream.end();
                resolve();
            });

            req.on('error', (err) => {
                stream.destroy(err);
                resolve();
            });
        })
    },
    move: function (pathname, destinationPath, allowOverwrite) {
        const sourceDiskPath = resolveDiskPath(pathname);
        const destDiskPath = resolveDiskPath(destinationPath);

        if (!fs.existsSync(sourceDiskPath)) return;

        const destDir = path.dirname(destDiskPath);
        if (!fs.existsSync(destDir)) fs.mkdirSync(destDir, { recursive: true });

        if (fs.existsSync(destDiskPath)) {
            if (!allowOverwrite) return;
            const destStat = fs.statSync(destDiskPath);
            if (destStat.isDirectory()) {
                fs.rmSync(destDiskPath, { recursive: true, force: true });
            } else {
                fs.unlinkSync(destDiskPath);
            }
        }

        try {
            fs.renameSync(sourceDiskPath, destDiskPath);
        } catch (err) {
            return;
        }
    },
    delete: function (pathname) {
        const diskPath = resolveDiskPath(pathname);
        if (fs.existsSync(diskPath)) {
            if (fs.statSync(diskPath).isDirectory()) {
                fs.rmSync(diskPath, { recursive: true, force: true })
            } else {
                fs.unlinkSync(diskPath);
            }
        }
    },
    mkdir: function (pathname) {
        const diskPath = resolveDiskPath(pathname);
        if (!fs.existsSync(diskPath)) {
            fs.mkdirSync(diskPath, { recursive: true });
        }
    }
});

Installation πŸ“¦

npm install webdav-serve

Troubleshooting πŸ› οΈ

If you encounter issues while writing files, try running the following commands as an administrator:

reg add HKLM\SYSTEM\CurrentControlSet\Services\WebClient\Parameters /v FileSizeLimitInBytes /t REG_DWORD /d 4294967295 /f
net stop webclient
net start webclient

These commands adjust the file size limit for the WebClient service on Windows, increasing it to 4GB.

❀️ DeveloperKubilay