Using memfs:
const { fs } = require('memfs');
fs.writeFileSync('/foo', 'hello');
console.log(fs.readFileSync('/foo/', 'utf8')); // logs 'hello'
Using the builtin fs (on Linux):
const fs = require('node:fs');
fs.writeFileSync('/foo', 'hello');
console.log(fs.readFileSync('/foo/', 'utf8')); // throws ENOTDIR
Using the builtin fs (on Windows):
const fs = require('node:fs');
fs.writeFileSync('C:/foo', 'hello');
console.log(fs.readFileSync('C:/foo/', 'utf8')); // logs 'hello'
I think a trailing slash means the path is intended to point at a folder, so trying to read from it should throw.
Not sure why Windows is weird, maybe the behavior should differ based on isWin.
Tested with memfs v4.11.1 and Node.js v20.12.2
Using
memfs:Using the builtin
fs(on Linux):Using the builtin
fs(on Windows):I think a trailing slash means the path is intended to point at a folder, so trying to read from it should throw.
Not sure why Windows is weird, maybe the behavior should differ based on
isWin.Tested with memfs v4.11.1 and Node.js v20.12.2