Hello there, I'm going through the learnyounode workshop, currently
on the Make It Modular section. I'm not getting a clear picture of how
modules work.
Suppose I want to create a new module named "mod1":
I would have to create a subfolder named "mod1" with files index.js and package.json. Does index.js contains the actual code, and package.json is simply descriptive?
The workshop doesn't seem to use said structure but instead simple uses a separate file for the exported function code. I think it has to do with using a single function export, rather that a full module that would contain any amount of function (I guess).
Even though I've created the subfolder with both files, when i ran the following from cli:
node -pe "require('mod1')"
I get
Error: Cannot find module 'mod1' error.
Any clarification to these is greatly appreciated, cheers!
I would have to create a subfolder named "mod1" with files index.js and package.json. Does index.js contains the actual code, and package.json is simply descriptive?
The workshop doesn't seem to use said structure but instead simple uses a separate file for the exported function code. I think it has to do with using a single function export, rather that a full module that would contain any amount of function (I guess).
Even though I've created the subfolder with both files, when i ran the following from cli:
node -pe "require('mod1')"
I get
Error: Cannot find module 'mod1' error.