最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Should I import 'fs' or 'node:fs' in Bun? - Stack Overflow

programmeradmin3浏览0评论

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?

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?

Share Improve this question edited Sep 10, 2023 at 16:49 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Sep 10, 2023 at 12:59 ABDULLOKH MUKHAMMADJONOVABDULLOKH MUKHAMMADJONOV 5,2846 gold badges27 silver badges50 bronze badges 1
  • 6 No difference. Always prefer the use of node: prefix for core modules that are shipped as part of Node. – Roko C. Buljan Commented Sep 10, 2023 at 13:09
Add a ment  | 

1 Answer 1

Reset to default 11

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 patible both ways.

发布评论

评论列表(0)

  1. 暂无评论