# Node.js: “ENOENT: no such file or directory”

> Error: ENOENT: no such file or directory. Build file paths from __dirname, not the working directory, and check the file is in the deploy.

Canonical: https://app369.com/fix/node-enoent-no-such-file-or-directory/
Last updated: 2026-11-07

A read, write or spawn fails with Error: ENOENT: no such file or directory, followed by a path. ENOENT means “no entry”: some part of that path does not exist at the moment the code runs. The path in the message is the one Node.js actually tried, which is often not the one you meant.

**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**

1. 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**](https://nodejs.org/api/process.html) 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+)
```
2. 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**](https://nodejs.org/api/errors.html) 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.
3. 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);
```
4. 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 November 7, 2026: [Node.js: Errors: Common system errors (ENOENT)](https://nodejs.org/api/errors.html); [Node.js: Process (process.cwd())](https://nodejs.org/api/process.html); [Node.js: Modules (__dirname)](https://nodejs.org/api/modules.html).

## **Rather hand it over?**

Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.

- [from $450**App Fix Ticket**One reproducible bug in an existing mobile or web app, diagnosed and fixed.**See scope and start**](https://app369.com/fixed-price/flutter-firebase-bug-fix/)
- [from $450**AI-Built App Rescue**A 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**](https://app369.com/fixed-price/ai-app-rescue/)

Related: [**Node.js “Cannot find module”**](https://app369.com/fix/node-cannot-find-module/) · [**Node.js EADDRINUSE: address already in use**](https://app369.com/fix/node-eaddrinuse-address-already-in-use/) · [**Vercel npm run build exited with 1**](https://app369.com/fix/vercel-npm-run-build-exited-with-1/) · [**Node.js ECONNRESET**](https://app369.com/fix/node-econnreset/)

Questions

## **More on this error**

<details>

<summary>**Why does the path work locally but not on the server? **+</summary>

Locally you start the app from the project folder, so relative paths happen to line up. The server or process manager may start it from another folder, and the file may not have been copied into the deploy at all. Use path.join(__dirname, ...) and check the file is in the build.

</details>

<details>

<summary>**What does the “no such file or directory” part mean exactly? **+</summary>

At least one part of the path is missing: the file itself or any folder above it. Node.js does not say which part, so check each folder in the path from the top down.

</details>

<details>

<summary>**Can you fix it for me? **+</summary>

If one bug is the whole problem, the App Fix Ticket covers it: a written diagnosis first, then the fix. If the app has more going on, the Launch Check is a written check of the whole app. Each issue found is rated critical, high, medium or low, with where it is and how it was confirmed. 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.

</details>

A different error?

## **Describe it and get a written quote**

Send the error and what you were doing. You get a written scope, a fixed price and a timeline; Simon replies by email, usually within one business day.

[**Describe your problem **→](https://app369.com/contact/) [**All fixes**](https://app369.com/fix/)