Cannot find module error in Node.js: Module not found due to incorrect path

I’m working on a Node.js project and I’ve encountered a Cannot find module error when trying to require a module. The error looks something like this:
Error: Cannot find module ”

I tried requiring the module in main.js and execute the node file with the following line of code

1.const myModule = require('myModule');
2.node index.js

1.I expected this to import the module without any issues since I assumed Node.js would locate it automatically. However, it threw a Cannot find module error instead. I checked that the file exists and is named mymodule.js, but it is in a different folder (modules).
2.Error occurs when we write wrong filepath and wrong file name