Skip to content

How to fix error: enoent: no such file or directory?

  • by
  • 4 min read
What is Metadata? Types and benefits | Candid.Technology

Web development has come a long way now. Instead of using simple HTML/CSS, Javascript and PHP to build websites, developers now can choose from plenty of web development frameworks and server tools that make the job easier. 

In this article, we’re looking at the “enoent: no such file or directory” error when running Node.js web servers, its causes and what you can do to fix the problem.


What causes this error?

As the error message describes, the problem is caused by a missing configuration file or other dependencies required for your website or web app to run properly. 

Other possible causes include the following:

  • Incorrect file paths for web server configuration files. 
  • NPM configuration folders aren’t made.

Also read: Fix: An unexpected error is keeping you from copying the file


How to fix this?

Here are five fixes you can try out. 

Restart your PC

A quick and simple fix for the problem is to restart your PC. This ensures that any missing processes start up correctly alongside your operating system and that everything is in order before running your project.


Create an NPM directory

One of the main reasons you’d run into this error is that NPM doesn’t have a configuration directory to keep track of your project’s dependencies. 

The simplest way to fix this is to run the npm install command. If that doesn’t work, you can also try running npm update. Running both commands back to back can also sometimes fix the problem. 

Also read: Docs.google.com refused to connect: 6 Fixes


Check your configuration files

Take a good look at the directory that the error message shows. The file at the end is the missing dependency that’s causing this problem. While it can be any of the dependencies in your project, this is often a missing configuration file. 

To resolve the error, you can manually create the mentioned file path with the specified file at the end. Do keep in mind that while it might fix the problem we’re dealing with in this article, it can give you additional errors, as the resulting file will be empty. 

Make sure your configuration files are in the right place and using the right Node version.

You can then work your way around the new error, if any, by installing any required packages that might be missing from your project. 


Fix the file path

As an extension to the last solution, you can also try and manually fix the file path that the error has reported missing. The specific way to do this varies from framework to framework, so you’ll have to look up the documentation of your specific framework in use to check how to modify file paths.

If you’re sure that the configuration file or dependencies exist, you can manually point your web server to the right file. 


Reinitialise your project

You also might have to reinitialise your project to freshen up all the dependencies you’re using. This can be done by deleting the node_modules folder and the package-lock.json file. Just open a terminal, head over to your project’s root folder and run the following commands one at a time.

rm -rf node_modules package-lock.json
npm install
Error: Cannot find module express: 3 Fixes

If you get an error saying you don’t have appropriate permissions to carry out these tasks, prefix sudo to both commands. 

Also read: Fix: Unknown error: soap-error: encoding: object has no uirequestid property

>