Reputation: 3843
I have a file inside the app folder.
What is the correct way to require it in Node?
I am using const to_be_required = require('./to_be_required.js');
But this give me this error:
module.js:549
throw err;
^
Error: Cannot find module 'got'
Upvotes: 0
Views: 58
Reputation: 146
Your syntax is correct, however the module you are trying to point to either does not exist or there is some other issue with where the module you are looking for is located. You need to understand what "./" means when requiring modules.
./ is same directory
../ is the previous directory (kind of like cd ..)
Node modules are different. You don't need to explicitly state where a particular module you want to require is. In this case, ./ is enough, but make sure you used npm install in order to install the node module.
Upvotes: 1
Reputation: 1243
That is the correct way to require files in Node. You may need to run npm install
or there's a typo in another file.
Upvotes: 2