ENOENT. No Such File or Directory
The file or directory specified in the operation does not exist.
Root Cause
The file path is wrong, the file was deleted, or the working directory is different from what you expect.
How to Fix
Verify the file path. Use path.resolve() to get the absolute path. Check the current working directory with process.cwd().
Quick Summary
ENOENT means the file or directory does not exist. Check the path for typos, verify the file exists, and use path.resolve() to debug absolute paths.
Key Takeaways
- The file or directory does not exist at the specified path
- Use path.resolve(filePath) to see the absolute path being accessed
- Check process.cwd() to verify the current working directory
- Use fs.existsSync() to check before accessing
When to use it
- Wrong file path in require() or fs.readFile()
- File was deleted or moved
- Different working directory in production vs development
Common Mistakes
- Using relative paths that work in development but break in production due to different working directories
- Not handling ENOENT in async file operations
ENOENT ENOENT. No Such File or Directory, Frequently Asked
How do I safely read a file that might not exist?
Use try/catch with fs.readFile, or check with fs.existsSync() first. In async code: try { const data = await fs.promises.readFile(path); } catch (e) { if (e.code === 'ENOENT') { /* handle missing file */ } }
Still having issues?
Check your network logs or use our developer tools to inspect headers, decode tokens, or validate your requests.