Categories
JavaScript Answers

How to fix Error: ENOENT, stat ‘./path/to/file’ error in Node.js?

Spread the love

To fix Error: ENOENT, stat ‘./path/to/file’ error in Node.js, we need to use the __dirname variable to access an absolute path in the project.

For instance, we write

const path = require("path");

const fullPath = path.join(__dirname, "path/to/file");

to call path.join to combine the project directory __dirname with the relative path in the project folder we want to access.

join returns the full path as a string.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *