I have the following code:
const fs = await import("fs");
let hashedPassword;
if (!fs.existsSync(".fs")) {
fs.mkdirSync(".fs");
console.info("No cache found. Creating .fs");
}
if (!fs.existsSync(".fs/token.txt")) {
console.info("No token found, hashing a new one");
hashedPassword = bcypt.hashSync(
password || (process.env.UNIVERSAL_FS_PASSWORD as string),
10
);
fs.writeFileSync(".fs/token.txt", hashedPassword);
}
// TODO: add correct url
const response = await fetch("http://localhost:3000/", {
headers: {
Authorization: `Bearer ${hashedPassword}`
}
});
if (response.status === 401) {
console.error("Failed to authenticate. Check your password");
} else if (response.status === 200) {
console.info("Authenticated");
} else if (response.status === 500) {
console.info("Something else went wrong. Check your server logs");
}
It checks if the .fs folder exists. If it does than the token is used for auth. If not it hashes a new one. The fs folder does not exists but when consoling the same fs.existsSync
I get the result true. However it does not exists.
Running the ls command where the exists call is checking shows that no .fs
folder exists:
README.md eslint.config.js package.json rollup.config.mjs tests types
dist node_modules pnpm-lock.yaml src tsconfig.json vite.config.ts
To get more info I consoled fs.stat
and this was the result:
Stats {
dev: 16777232,
mode: 33188,
nlink: 1,
uid: 501,
gid: 20,
rdev: 0,
blksize: 4096,
ino: 52057046,
size: 60,
blocks: 8,
atimeMs: 1719445593768.046,
mtimeMs: 1719445593768.1392,
ctimeMs: 1719445593768.1392,
birthtimeMs: 1719445593768.046
}
It seems Node still thinks the dir and file exist on my system. Envinfo:
System:
OS: macOS 14.5
CPU: (12) arm64 Apple M2 Max
Memory: 8.82 GB / 32.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 22.3.0 - /opt/homebrew/bin/node
npm: 10.8.1 - /opt/homebrew/bin/npm
pnpm: 9.4.0 - ~/Library/pnpm/pnpm
bun: 1.1.17 - ~/.bun/bin/bun
Managers:
Homebrew: 4.3.7 - /opt/homebrew/bin/brew
pip3: 24.0 - /opt/homebrew/bin/pip3
RubyGems: 3.0.3.1 - /usr/bin/gem
Utilities:
Make: 3.81 - /usr/bin/make
GCC: 15.0.0 - /usr/bin/gcc
Git: 2.39.3 - /usr/bin/git
Clang: 15.0.0 - /usr/bin/clang
FFmpeg: 7.0.1 - /opt/homebrew/bin/ffmpeg
Curl: 8.6.0 - /usr/bin/curl
OpenSSL: 3.3.1 - /opt/homebrew/bin/openssl
Servers:
Apache: 2.4.58 - /usr/sbin/apachectl
Virtualization:
Docker: 26.1.4 - /usr/local/bin/docker
Docker Compose: 2.27.1 - /usr/local/bin/docker-compose
Parallels: 19.3.0 - /usr/local/bin/prlctl
SDKs:
iOS SDK:
Platforms: DriverKit 23.5, iOS 17.5, macOS 14.5, tvOS 17.5, visionOS 1.2, watchOS 10.5
IDEs:
VSCode: 1.90.2 - /usr/local/bin/code
Vim: 9.0 - /usr/bin/vim
Xcode: 15.4/15F31d - /usr/bin/xcodebuild
Languages:
Bash: 3.2.57 - /bin/bash
Java: 21.0.2 - /usr/bin/javac
Perl: 5.34.1 - /usr/bin/perl
Python3: 3.12.3 - /opt/homebrew/bin/python3
Ruby: 2.6.10 - /usr/bin/ruby
Databases:
SQLite: 3.43.2 - /usr/bin/sqlite3
Browsers:
Safari: 17.5