ENOENT 🟩 Node.js

Error: ENOENT: no such file or directory

A file or directory the program tried to open doesn’t exist at that path.

Seen on: Node.js npm

Meaning

Relative paths resolve from the process’s current working directory, not the script file — so code that works from one folder fails from another. In npm, “ENOENT … package.json” means you ran npm outside the project folder.

Common causes

  • Relative path resolved from a different working directory
  • File not created/copied (build output, uploads, Docker COPY)
  • npm command run outside the project (no package.json)
  • Case mismatch on Linux
  • Executable not found when spawning (spawn git ENOENT)

⚡ Quick fix

  1. Build paths from the script location: path.join(__dirname, 'data.json')
  2. Check the exact path in the error exists
  3. Run npm in the folder with package.json
  4. For spawn X ENOENT, install X or fix PATH

Detailed fix by platform

Node.js

  1. Robust path:
    javascript
    const file = path.join(__dirname, 'config', 'settings.json');

How to diagnose

  1. Path — Exact path in the error
  2. CWD — process.cwd() at runtime
  3. Exists — Is the file present in this environment?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.