Why Node.js needs a virtual file system

(blog.platformatic.dev)

57 points | by voctor 1 hour ago

13 comments

  • indutny 15 minutes ago
    Taking the question of whether this would be a useful addition to Node.js core or aside, it must be noted that this 19k LoC PR was mostly generated by Claude Code and manually reviewed by the submitter which is my opinion is against the spirit of the project and directly violates the terms of Developer's Certificate of Origin set in the project's CONTRIBUTING.md
    • epolanski 13 minutes ago
      Do as I say, not as I do.

      On a more serious note, I think that this will be thoroughly reviewed before it gets merged and Node has an entire security team that overviews these.

      • indutny 1 minute ago
        As someone who was a part of the aforementioned security team I'm not sure I'd be interested in reviewing such volume of machine generated code, expecting trap at every corner. The implicit assumption that I observed at many OSS projects I've been involved with is that first time contributions are rarely accepted if they are too large in volume, and "core contributor" designation exists to signal "I put effort into this code, stand by it, and respect everyone's time in reviewing it". The PR in the post violates this social contract.
  • wccrawford 1 hour ago
    I'm not convinced that allowing Node to import "code generated at runtime" is actually a good thing. I think it should have to go through the hoops to get loaded, for security reasons.

    I like the idea of it mocking the file system for tests, but I feel like that should probably be part of the test suite, not Node.

    The example towards the end that stores data in a sqlite provider and then saves it as a JSON file is mind-boggling to me. Especially for a system that's supposed to be about not saving to the disk. Perhaps it's just a bad example, but I'm really trying to figure out how this isn't just adding complexity.

    • TheRealPomax 47 minutes ago
      But then you go "hang on, doesn't ESM exist?" and you realize that argument 4 isn't even true. You can literally do what this argument says you can't, by creating a blob instead of "writing a temp file" and then importing that using the same dynamic import we've had available since <checks his watch> 2020.
  • notnullorvoid 8 minutes ago
    I could see something like this being useful if it could be passed to workers to replace any fs access inside the worker.
  • austin-cheney 1 hour ago
    Most of the 4 justifications mentioned sound like mitigations of otherwise bad design decisions. JavaScript in the browser went down this path for the longest time where new standards were introduced only to solve for stupid people instead of actually introducing new capabilities that were otherwise unachievable.

    I do see some original benefits to a VFS though, bad application decisions aside, but they are exceedingly minor.

    As an aside I think JavaScript would benefit from an in-memory database. This would be more of language enhancement than a Node.js enhancement. Imagine the extended application capabilities of an object/array store native to the language that takes queries using JS logic to return one or more objects/records. No SQL language and no third party databases for stuff that you don't want to keep in offline storage on a disk.

  • Normal_gaussian 9 minutes ago
    yarn pnp is currently broken on Node v25.7+;

    - https://github.com/yarnpkg/berry/issues/7065

    - https://github.com/nodejs/node/issues/62012

    This is because yarn patches fs in order to introduce virtual file path resolution of modules in the yarn cache (which are zips), which is quite brittle and was broken by a seemingly unrelated change in 25.7.

    The discussion in issue 62012 is notable - it was suggested yarn just wait for vfs to land. This is interesting to me in two ways: firstly, the node team seems quite happy for non-trivial amounts of the ecosystem to just be broken, and suggests relying on what I'm assuming will be an experimental API when it does land; secondly, it implies a lot of confidence that this feature will land before LTS.

  • mg 34 minutes ago

        You can’t import or require() a module
        that only exists in memory.
    
    You can convert it into a data url and import that, can't you?
    • doctorpangloss 33 minutes ago
      Yeah but Claude didn't suggest that when it wrote this blog post and did all the work so...
  • PaulHoule 1 hour ago
    Would be nice if node packages could be packed up in ZIP files so to avoid the security/metadata tax for small file access on Windows.
    • MarleTangible 1 hour ago
      The number of files in the node modules folder is crazy, any amount of organization that can tame that chaos is welcomed.
      • koolba 31 minutes ago
        And if you thought malware hiding in a mess of files was bad, just wait till you see it in two layers of container files.
        • PaulHoule 3 minutes ago
          Or worse yet, the performance load of anti-malware software that has to look inside ZIP files.

          Look, most of us realized around 2004 or so that if you had a choice between Norton and the virus you would pick the virus. In the Windows world we standardized around Defender because there is some bound on how much Defender degrades the performance of your machine which was not the case with competitive antivirus software.

          I've done a few projects which involved getting container file formats like ZIP and PDF (e.g. you know it's a graph of resources in which some of those resources are containers that contain more resources, right?) and now that I think of it you ought to be able to virus scan ZIP files quickly and intelligently but the whole problem with the antivirus industry is that nobody ever considers the cost.

    • Dangeranger 39 minutes ago
      There are alternative package managers like Yarn that use zip files as a way to store each Node package.[0]

      [0] https://yarnpkg.com/advanced/pnp-spec#zip-access

      • PaulHoule 2 minutes ago
        ... and of course JAR files in Java are just ZIP files with a little extra metadata and the JVM can unpack them in realtime just fine.
    • fmorel 1 hour ago
      I remember when Firefox started putting everything into jars for similar reasons.

      https://web.archive.org/web/20161003115800/https://blog.mozi...

    • MBCook 29 minutes ago
      It’s insane to me that node works how it does. Zip files make so much more sense, I really liked that about Yarn.
    • sheept 54 minutes ago
      Would it work to run a bundler over your code, so all (static) imports are inlined and tree shaken?
  • ozlikethewizard 19 minutes ago
    I'm not convinced this needs to be in core Node, but being able to have serverless functions access a file system without providing storage would definitely have some use cases. Had some fun with video processing recently that this would be perfect for.
  • westurner 48 minutes ago
    Is node::vfs the new solution for JupyterLite filesystems?

    From https://github.com/jupyterlite/jupyterlite/issues/949#issuec... :

    > Ideally, the virtual filesystem of JupyterLite would be shared with the one from the virtual terminal.

    emscripten-core/emscripten > "New File System Implementation": https://github.com/emscripten-core/emscripten/issues/15041#i... :

    > [ BrowserFS, isomorphic-git/lightningfs, ]

    pyodide/pyodide: "Native file system API" #738: https://github.com/pyodide/pyodide/issues/738 re: [Chrome,] Filesystem API :

    > jupyterlab-git [should work with the same VFS as Jupyter kernels and Terminals]

    pyodide/pyodide: "ENH Add API for mounting native file system" #2987: https://github.com/pyodide/pyodide/pull/2987

  • moralestapia 1 hour ago
    >Let me be honest: a PR that size would normally take months of full-time work. This one happened because I built it with Claude Code.

    The node.js codebase and standard library has a very high standard of quality, hope that doesn't get washed out by sloppy AI-generated code.

    OTOH, Matteo is an excellent engineer and the community owes a lot to him. So I guess the code is solid :).

  • leontloveless 15 minutes ago
    [dead]
  • andrewmcwatters 1 hour ago
    [dead]
  • petcat 1 hour ago
    Are people still building new projects on Node.js? I would have thought the ecosystem was moving to deno or bun now
    • dzogchen 1 hour ago
      I don't really understand what the value proposition of Bun and Deno is. And I see huge problems with their governance and long-term sustainability.

      Node.js on the other hand is not owned or controlled by one entity. It is not beholden to the whims of investors or a large corporation. I have contributed to Node.js in the past and I was really impressed by its rock-solid governance model and processes. I think this an under-appreciated feature when evaluating tech options.

    • jitl 1 hour ago
      loud people on twitter are always switching to the new hotness. i personally can't see myself using bun until its reputation for segfaults goes away after a few more years of stabilizing. deno seems neat and has been around for longer, but its node compatibility story is still evolving; i'm also giving it another year before i try it.
    • rrr_oh_man 1 hour ago
      Why?
    • kitsune1 1 hour ago
      The delusion in this comment is insane.