Matias Salimbene
2018-08-05 14:01:48 UTC
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!
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/3cbca44d-ee42-4438-9401-dce2788f7837%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
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!
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/3cbca44d-ee42-4438-9401-dce2788f7837%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.