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

directus-extension-ensure-folders

v1.0.4

Published

Create folders for the directus files system in hirarchy. Use this directus operation extension in a directus flow to ensure that the folder hirarchy exist.

Readme

Ensure Folders

Directus Flow Operation: Ensure Folders

A small Directus operation extension that idempotently ensures a hierarchy of up to 5 nested folders (folder1..folder5) in the Directus folders collection. It will reuse existing folders found by name (scoped by parent) or create them if missing, threading the parent folder id through each level.

options.jpg

Behavior / contract

  • Inputs (options):
    • folder1 (string, required) — top-level folder name
    • folder2 (string, optional)
    • folder3 (string, optional)
    • folder4 (string, optional)
    • folder5 (string, optional)
  • Outputs: a flat object with keys folder1, folder2, folder3, folder4, folder5, and lastFolder. Each value is a folder id (string) or null when not provided or not created.
  • Logic:
    • Iterates i = 1..5. For each folder{i} that is a non-empty string, it:
      • Looks for an existing folder with the same name and the current parent value (null for top-level).
      • If found, uses its id; otherwise creates a new folder with name and parent.
      • Sets parent to the found/created id for the next level.
    • Stops early when it encounters the first empty/missing folder name and returns the current result.
    • Idempotent: running the operation multiple times with the same names returns the same ids and does not create duplicates.
    • Handles a race when creating a folder by retrying the lookup if creation fails with a conflict.

Response shape (example)

{
  "folder1": "a1b2c3...",
  "folder2": "d4e5f6...",
  "folder3": null,
  "folder4": null,
  "folder5": null,
  "lastFolder": "d4e5f6..."
}
  • lastFolder equals the id of the deepest created/found folder (the last non-empty folder). If only folder1 is supplied, lastFolder equals folder1's id.

Usage (Directus Flow Operation)

  • Add the ensure-folders operation to a Flow.
  • Provide folder1 (required) and optionally folder2..folder5.
  • The operation returns the object (above) which can be used by downstream operations.

Example payload (when invoking via API or testing in the Flow UI)

{
  "folder1": "Tenants",
  "folder2": "Project X",
  "folder3": "CollectionName"
}

Development / installation

  1. Place this extension in /directus/extensions/ensure-folders (build result of this repo).
  2. Restart Directus so it discovers the extension.
  3. Use the Flow builder to add the ensure-folders operation.

License & Contributing

Any use of this plugin in a commercial or public product must visibly mention the original author and repository. Apache 2.0 License.