In this lesson, you'll learn the difference between the exports statement and Module.exports. Examples is demonstrated, each accomplishing the same task but one using export statements and one using Module.expor Ts. You'll also learn the basic thumb rule to identify which are appropriate for your current needs.
// Circle.js using the EXPORTS statement var Pi =function(r) { return PI * R *function(r) { return 2 * Pi * r;}
// accessing the exported functions in the node shell var circle = require ('./circle.js '); Circle.area (4); Circle.circumference (4);
---------------------
// using Module.exports to demonstrate the same functionality var PI =function(r) { return { function() { return PI * R * r; }, function() { return 2 * PI * r; }}
// accessing the exposed functions in the node shell var circle = require ('./circle.js '); var mycircle = Circle (4); Mycircle.area (); Mycircle.circumference ();
To summarize this, the general thumb-rule is with the exports statement to export instances of modules. Use the Module.exports statement to export JavaScript objects.
[Node. js] Exporting Modules in Node