Reputation: 898
Regarding this question: What is the purpose of Node.js module.exports and how do you use it?
I'm a Javascript beginner. In the referenced question...
mymodule.js code
var myFunc = function() { ... };
exports.myFunc = myFunc;
main js file
var m = require('./mymodule.js');
m.myFunc();
Is mymodule essentially a class file defining objects?
Upvotes: 2
Views: 622
Reputation: 18827
Node.js allows code to be separated into different modules. This modules are just javascript files that can expose functions or objects using the exports
object.
There are no Classes in JavaScript but you can use patterns to emulate that behaviour. There is a question about implementing OOP patterns in JavaScript: what pattern to use when creating javascript class?
As a beginner there are very good books for JavaScript:
They are short and will give you a very good insight of the JavaScript Language.
Upvotes: 4
Reputation: 339816
Is mymodule essentially a class file defining objects?
and functions, although in Javascript functions are objects, so the distinction may be moot.
Importantly, each module has its own scope, so any var
declared therein will not be visible outside of the module.
The rest of your question about users and lists doesn't make sense as written. Javascript OO programming is a complete topic in its own right, and the module system doesn't really change that. Modules are just a way of wrapping code libraries.
Upvotes: 2