-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.js
More file actions
17 lines (14 loc) · 749 Bytes
/
module.js
File metadata and controls
17 lines (14 loc) · 749 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
//Module Example
//Node wraps each file in a IFFE function declaration, passing exports, require, module, _filename, and _dirname
//Arguments passed to IFFE
console.log(__filename); //Complete path to the current file
console.log(__dirname); //Path to directory that contains this module
console.log(module); //Representation of the current file
console.log(require); //Function used for grabbing exported modules for use in a file
function log(message) {
console.log(message);
}
//How to export something from a module
module.exports.log = log; //Method on exports object, access with .log
module.exports = log; //Method as exports object, access by calling instance
exports.log = log; //Method as exports object, access by calling instance