Coggle requires JavaScript to display documents.
const fs = require('fs');
math.js
const add = (x, y) => x + y; const PI = 3.14159; const square = x => x * x;
app.js
const math = require("./math"); console.log(math);
> node app.js
> {}
module.exports
... module.exports = "HELLO!";
> HELLO!
... module.exports.add = add; module.exports.PI = PI; module.exports.square = square;
> { add: [Function: add], PI: 3.14159, square: [Function: square] }
math.add(3,4);
... const math = { add: add, PI: PI, square: square, }; module.exports = math;
... exports = math;
index.js
barney.js
module.exports = { name: "Barney", colour: "fawn and white", description: "baby hippo" }
fred.js
module.exports = { name: "Fred", colour: "tan and white", description: "lioness" }
const fred = require("./fred"); const barney = require("./barney"); const dogs = [fred, barney]; console.log(dogs);
> node index.js
> [ { name: 'Fred', ... }, { name: 'Barney', ...'} ]
/dogs - barney.js - fred.js - index.js
... module.exports = dogs;
const dogs = require("./dogs");
require()