Short answer
Look at the full path in the error. If it is relative (like ./data/config.json), Node.js resolved it from the folder you started the process in, not from the file’s folder: build it with path.join(__dirname, ...) instead. If the path looks right, the file is missing at runtime: it was not copied into the build or Docker image, a folder needs creating first (fs.mkdir with recursive: true), or a serverless host only has a writable /tmp. During npm install, ENOENT on package.json means you ran npm in the wrong folder.
Why the path does not exist, and the fix
01
A relative path resolved from the wrong folder
“The process.cwd() method returns the current working directory of the Node.js process.” Node.js, Process
fs resolves relative paths from the working directory, which is wherever you ran node, npm or the process manager. Run the same script from another folder, or from a host that starts it elsewhere, and the path points somewhere else. Build paths from the file’s own folder instead.
const path = require('node:path'); const fs = require('node:fs'); const file = path.join(__dirname, 'data', 'config.json'); const config = JSON.parse(fs.readFileSync(file, 'utf8')); // ES modules: const dir = import.meta.dirname; (Node 20.11+)02
The file was not deployed
“Commonly raised by fs operations to indicate that a component of the specified pathname does not exist.” Node.js, Errors: Common system errors
Files that code reads at runtime (templates, JSON, certificates, uploads) are not always copied into the build output, the Docker image or the serverless bundle. Check the COPY lines in the Dockerfile, the files field in package.json, or the host’s include settings, and log the path before reading it.
03
Writing into a folder that does not exist
writeFile does not create missing parent folders, so writing logs/2026/app.log fails until logs/2026 exists. Create the folder first. On serverless hosts, only /tmp is writable, and it is not shared between instances and can be wiped between runs, so keep anything permanent in storage.
await fs.promises.mkdir(path.dirname(file), { recursive: true }); await fs.promises.writeFile(file, data);04
npm or a spawned command cannot find its target
npm error enoent (older npm: npm ERR! enoent) ... package.json means the terminal is not in the project folder: cd into the folder that holds package.json. spawn ENOENT means the program you started (git, python, ffmpeg) is not installed or not on the PATH of that process, which happens often in slim Docker images. On Windows, spawn('npm') needs npm.cmd or shell: true.
Checked against the vendor’s docs on : Node.js: Errors: Common system errors (ENOENT); Node.js: Process (process.cwd()); Node.js: Modules (__dirname).
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way. This applies to the first 10 Launch Checks bought after October 30, 2026.See scope and start
Related: Node.js “Cannot find module” · Node.js EADDRINUSE: address already in use · Vercel npm run build exited with 1 · Node.js ECONNRESET