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.