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 🙏

© 2026 – Pkg Stats / Ryan Hefner

vanilla-filemanager

v1.2.1

Published

Vanilla Javascript filemanager

Downloads

13

Readme

Get Started Guide

This guide will help you get started with the vanilla-filemanager JavaScript library.

You can find the complete code for connecting, configuring the library, and the server-side part here.

What is File Manager?

File Manager is a JavaScript library that provides a widget for working with files and folders. It allows users to browse, upload, delete, rename, and perform other basic file operations directly in a web interface.

Prerequisites

  • Basic knowledge of JavaScript, HTML, and CSS.
  • Installed Node.js and npm (or yarn) for dependency management (if you are using a module bundler).
  • A backend capable of handling HTTP requests for file operations (read, write, delete, etc.).
  • Any module bundler, if you don't want to use a CDN.

Step 1: Install and Import the Library

You can install the File Manager library in several ways:

Method 1: Using CDN (Content Delivery Network)

The easiest way to get started is to use a CDN. Add the following <script> tag to your HTML file:

<script src="https://unpkg.com/vanilla-filemanager"></script>

Method 2: Installing with npm (or yarn)

If you are using a module bundler, install the library via npm:

npm install vanilla-filemanager

Import the library into your JavaScript file:

import { FileManager, FileManagerServer } from 'vanilla-filemanager';

Step 2: Creating a Server Class

The File Manager library interacts with a server to perform file operations. You need to create a class that extends FileManagerServer and implements methods for interacting with your backend. Example:

import { FileManager, FileManagerServer } from 'https://unpkg.com/vanilla-filemanager';

class MyFileManagerServer extends FileManagerServer {
    async getFolders(path) {
        const url = '/get-folders';
    
        const body = JSON.stringify({ path: path });

        const res = await fetch(url, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: body
        });
    
        try {
            if (!res.ok) { 
                throw new Error(`Ошибка сервера: ${res.status}`);
            }
    
            const data = await res.json();
            return data.folders;
    
        } catch (error) {
            const errorText = await res.text();
            throw new Error(`HTTP Error: ${res.status} - ${res.statusText}, Body: ${errorText}`);
        }
    }

    async getFiles(path) {
        const url = '/get-files';
    
        const body = JSON.stringify({ path: path });
    
        const res = await fetch(url, {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json'
            },
            body: body
        });
        try {
            if (!res.ok) { 
                throw new Error(`Ошибка сервера: ${res.status}`);
            }
    
            const data = await res.json();
    

            return data.files;
    
        } catch (error) {
            const errorText = await res.text();
            throw new Error(`HTTP Error: ${res.status} - ${res.statusText}, Body: ${errorText}`);
        }
    }

    async uploadFile(file, path) {
        const formData = new FormData();

        formData.append('path', path);
        formData.append('files', file);

        const response = await fetch('/upload', {
            method: 'POST',
            body: formData,
        });

        if (response.ok) {
            console.log("Всё ок!");

            return true;
        } 
        else {
            const errorText = await res.text();
            throw new Error(`HTTP Error: ${res.status} - ${res.statusText}, Body: ${errorText}`);
        }
    }

    ...
}

Explanation of the methods:

  • getFolders(path): Gets a list of folders in the specified path.
  • getFiles(path): Gets a list of files in the specified path.
  • uploadFile(file, path): Uploads a single file to the specified path.
  • uploadFolder(files, path): Uploads multiple files to the specified path (for folder uploads).
  • removeFileOrFolder(path): Deletes a file or folder at the specified path.
  • renameFileOrFolder(oldPath, newPath): Renames a file or folder.
  • copyFileOrFolder(oldPath, newPath): Copies a file or folder.
  • downloadFiles(paths): Downloads files as an archive.
  • searchFiles(searchString, path): Performs a file search.
  • createEmptyFile(path): Creates an empty file.
  • createEmptyFolder(path): Creates an empty folder.

Important:

  • Specify the correct URLs (/get-folders, /get-files, /upload, etc.) for your server-side handlers.
  • Implement error handling and data return logic according to your backend.
  • Ensure that your backend handles requests securely to prevent unauthorized access to files.

Step 3: Creating a File Manager Instance and Initialization

  1. HTML Container: Add an HTML element that will serve as a container for the File Manager widget.
<div class="somediv"></div>
  1. Initialization: In your JavaScript code, create an instance of MyFileManagerServer and then FileManager, passing the container, the server instance, and options:
import { FileManager, FileManagerServer } from 'https://unpkg.com/vanilla-filemanager';

// Your MyFileManagerServer class (see step 2)

function main() {
    const icons = {
        addFile: "/icons/add_file.png",
        addFolder: "/icons/add_folder.png",
        arrowDownFolder: "/icons/arrow-point-to-down.png",
        arrowRightFolders: "/icons/arrow-point-to-right.png",
        arrowRightNavigation: "/icons/arrow-right.png",
        cut: "/icons/cut.png",
        copy: "/icons/copy.png",
        folder: "/icons/folder2.png",
        settings: "/icons/gear.png",
        grid: "/icons/grid.png",
        insert: "/icons/insert.png",
        arrowBack: "/icons/next-left.png",
        arrowUp: "/icons/next-upper.png",
        refresh: "/icons/refresh.png",
        picture: "/icons/picture.png",
        remove: "/icons/remove.png",
        rename: "/icons/rename.png",
        addFilesButton: "/icons/sticky-notes.png",
        list: "/icons/list.png",
        textfile: "/icons/textfile.png",
        openedFolder: "/icons/open-folder.png",
        download: "/icons/download.png",
        createFile: "/icons/create-file.png",
        createFolder: "/icons/create-folder.png",
        css: "/icons/css.png",
        doc: "/icons/doc.png",
        docx: "/icons/docx.png",
        exe: "/icons/exe.png",
        html: "/icons/html.png",
        mp4: "/icons/mp4.png",
        pdf: "/icons/pdf.png",
        php: "/icons/php.png",
        ppt: "/icons/ppt.png",
        pptx: "/icons/pptx.png",
        py: "/icons/python-file.png",
        svg: "/icons/svg.png",
        wav: "/icons/wav.png",
        xls: "/icons/xls.png",
        xlsx: "/icons/xlsx.png",
        zipFolder: "/icons/zip-folder.png"
    }

    const customStyles = {
        "fm_folders_nav": {
            border: "3px solid red"
        }
    }

    const customLanguages = {
        es: {
            "Upload": "Subir",
            "Searching": "Buscando",
            "Upload file": "Subir archivo",
            "Upload folder": "Subir carpeta",
            "Settings": "Configuración",
            "Hover color": "Color al pasar el ratón",
            "Background color": "Color de fondo",
            "Border color": "Color del borde",
            "Select color": "Seleccionar color",
            "Text color": "Color del texto",
            "Address Pane interface": "Interfaz del panel de dirección",
            "Tools Pane interface": "Interfaz del panel de herramientas",
            "Navigation Pane interface": "Interfaz del panel de navegación",
            "Content Pane interface": "Interfaz del panel de contenido",
            "Settings Pane interface": "Interfaz del panel de configuración:",
            "medium": "mediano",
            "xsmall": "extra pequeño",
            "small": "pequeño",
            "large": "grande",
            "xlarge": "extra grande",
            "To default": "Por defecto",
            "Submit": "Enviar",
            "Success": "Éxito",
            "Refresh": "Actualizar",
            "Up": "Arriba",
            "Back": "Atrás",
            "This folder is empty.": "Esta carpeta está vacía.",
            "Cut file/folder": "Cortar archivo/carpeta",
            "Copy file/folder": "Copiar archivo/carpeta",
            "Paste file/folder": "Pegar archivo/carpeta",
            "Rename file/folder": "Renombrar archivo/carpeta",
            "Remove file/folder": "Eliminar archivo/carpeta",
            "Download file/folder": "Descargar archivo/carpeta",
            "Create empty file": "Crear archivo vacío",
            "Create empty folder": "Crear carpeta vacía",
            "Name": "Nombre",
            "Date of change": "Fecha de modificación",
            "Type": "Tipo",
            "Size": "Tamaño",
            "Byte": "Byte",
            "Folder": "Carpeta",
            "file": "archivo",
            "Change file display to list": "Cambiar visualización de archivos a lista",
            "Change file display to tiles": "Cambiar visualización de archivos a mosaicos",
            "MB": "MB",
            "KB": "KB",
            "Image": "Imagen",
            "Are you sure you want to reset?": "¿Estás seguro de que quieres restablecer?",
            "Are you sure you want to delete?": "¿Estás seguro de que quieres eliminar?",
            "Are you sure you want to download?": "¿Estás seguro de que quieres descargar?"
        }
    }

    const options = {
        rootFolderName: "Root",
        icons: icons,
        language: "ru",
        addressPaneOptions: {
            addressPaneEnabled: true,
            searchingEnabled: true,
            refreshButtonEnabled: true,
            upButtonEnabled: true,
            backButtonEnabled: true,
        },
        toolsPaneOptions: {
            toolsPaneEnabled: true,
            uploadingFilesEnabled: true,
            toolsEnabled: {
                deletingFiles: true,
                renamingFiles: true,
                downloadingFiles: true,
                movingFiles: true,
                createFiles: true,
            },
            defaultFileDisplayMode: "list",
            fileDisplayModesEnabled: true,
            settingsOptions: {
                settingsEnabled: true,
                colorSettingsEnabled: true,
                sizeSettingsEnabled: true,
            },
        },
        navigationPaneEnabled: true,
    }


    const filemanagerRoot = document.querySelector(".somediv");
        
    const myFileManagerServer = new MyFileManagerServer();
    const filemanager = new FileManager(filemanagerRoot, myFileManagerServer, options, customStyles, customLanguages);

}

main();

Step 4: Configuring the Backend

You will need to create a backend that handles requests from the File Manager. The backend should:

  • Provide an API to get a list of folders and files in the specified path.
  • Handle file uploads.
  • Implement deletion, renaming, and copying of files/folders.
  • Provide the ability to download files as an archive.
  • Perform file searches.
  • Create empty files and folders.

Step 5: Customizing Appearance and Behavior (Optional)

You can customize the File Manager by passing an options object to the FileManager constructor:

  • rootFolderName: The name of the root folder.
  • icons: An object with paths to custom icons.
  • language: The interface language (e.g., "ru", "en").
  • addressPaneOptions: Address bar settings (enable/disable, search, buttons).
  • toolsPaneOptions: Toolbar settings (enable/disable, file upload, tools).
  • navigationPaneEnabled: Enable/disable the navigation panel.
  • customStyles: Styles for overriding the default library styles.
  • customLanguages: Object with translations for different languages.

const options = {
    rootFolderName: "Root",
    icons: icons,
    language: "ru",
    addressPaneOptions: {
        addressPaneEnabled: true,
        searchingEnabled: true,
        refreshButtonEnabled: true,
        upButtonEnabled: true,
        backButtonEnabled: true,
    },
    toolsPaneOptions: {
        toolsPaneEnabled: true,
        uploadingFilesEnabled: true,
        toolsEnabled: {
            deletingFiles: true,
            renamingFiles: true,
            downloadingFiles: true,
            movingFiles: true,
            createFiles: true,
        },
        defaultFileDisplayMode: "list",
        fileDisplayModesEnabled: true,
        settingsOptions: {
            settingsEnabled: true,
            colorSettingsEnabled: true,
            sizeSettingsEnabled: true,
        },
    },
    navigationPaneEnabled: true,
}

You can find the complete code for connecting, configuring the library, and the server-side part here