I'm learning Node.js and writing a simple module using the Visual Studio 2015 Node.JS extension.
I know ./
means 'look for the file in the same directory'. But in most systems I've seen (say, #include
in C++) the forwarding ./
is optional. I've tried to remove it but it turns out Node.js cannot find modules without the prefix. For me it seems ugly, so is it really mandatory? If yes, why?
Regards,
With require('./script_name')
, you can include another JS within the same folder, as you know already.
When you require('module_name')
without the ./
, Node.JS looks at the node_modules
folder for a module with this name. Optionally, you can call it's public methods or pass it arguments.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With