Why Bun Give Unsorted Output Files in Read Directory? #14383
Answered
by
Jarred-Sumner
kresnasatya
asked this question in
Q&A
-
Hi everyone! I create a script to get list of files inside of directory named
Here's the script. // index.js
import path from 'node:path';
import fs from 'node:fs/promises';
(async () => {
const files = await fs.readdir(path.join(process.cwd(), 'books'));
for (const file of files) {
console.log(file);
}
})(); If I run // node index.js
a.md
b.md
c.md
d.md
z.md Meanwhile, if I run // bun index.js <= Run this command many times and I get the exact output below.
b.md
z.md
c.md
d.md
a.md I'm using Bun version 1.1.26 on macOS M1. I'm curious why does it happened? Is that design by default or is it bug? |
Beta Was this translation helpful? Give feedback.
Answered by
Jarred-Sumner
Oct 6, 2024
Replies: 1 comment 3 replies
-
This is consistent with Node.js - the operating system determines what sorting order to use, which is essentially random |
Beta Was this translation helpful? Give feedback.
3 replies
Answer selected by
kresnasatya
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is consistent with Node.js - the operating system determines what sorting order to use, which is essentially random