Search code examples
javascriptnode.jsnode.js-fsbun

Should I import 'fs' or 'node:fs' in Bun?


I am trying to migrating my Node.js project to Bun. My project uses the 'fs' package in many places. I found many Bun migration examples where they import the 'fs' package as 'node:fs'. But importing as 'fs' works fine without any errors and performance issues.

Should I leave my imports as 'fs' or change to 'node:fs' (and other packages that can be imported as 'node:...')? Are there performance differences?


Solution

  • I wouldn't imagine there are differences. (Try importing both and see if they're the same object with ===?)

    You can also import fs in Node as node:fs (so as to make it clear it's an internal module), so both are compatible both ways.