Awesome explanation: https://stackoverflow.com/questions/31354559/using-node-js-require-vs-es6-import-export
Took a snapshot of the Stack Overflow Question and Answer just in case if in case I won't find that page again:
Showing posts with label require. Show all posts
Showing posts with label require. Show all posts
Tuesday, September 19, 2017
Sunday, March 13, 2016
Dojo define() Vs require()
This is the simplest explanation that I come across that explained the differences between dojo define() and require(){
http://g00glen00b.be/dojo-require-vs-define/
http://g00glen00b.be/dojo-require-vs-define/
Sunday, April 5, 2015
module.exports in Node.js
Suppose you want to write a module, say a functions module and access it in another module, say main.js, how are you going to do it in Node.js?
Real simple!
Create two .js files under C:\nodetest folder: functions.js, main.js
functions.js
module.exports = { addNumbers : function() { var total = 0; for (var a = 0; a < arguments.length; a++){ total += parseInt(arguments[a]); } return total; }, findArea : function(r){ return 3.142 * r * r; } };
functions.js:
this.addNumbers = function() { var total = 0; for (var a = 0; a < arguments.length; a++){ total += parseInt(arguments[a]); } return total; }; this.findArea = function(r){ return 3.142 * r * r; };
main.js
var functions = require('./functions.js'); console.log(functions.addNumbers(1,2)); console.log(functions.findArea(2));
Run the main.js from command prompt!
C:\nodetest>node main
Reference:
http://www.sitepoint.com/understanding-module-exports-exports-node-js/
Real simple!
Create two .js files under C:\nodetest folder: functions.js, main.js
functions.js
module.exports = { addNumbers : function() { var total = 0; for (var a = 0; a < arguments.length; a++){ total += parseInt(arguments[a]); } return total; }, findArea : function(r){ return 3.142 * r * r; } };
or
this.addNumbers = function() { var total = 0; for (var a = 0; a < arguments.length; a++){ total += parseInt(arguments[a]); } return total; }; this.findArea = function(r){ return 3.142 * r * r; };
main.js
var functions = require('./functions.js'); console.log(functions.addNumbers(1,2)); console.log(functions.findArea(2));
Run the main.js from command prompt!
C:\nodetest>node main
Reference:
http://www.sitepoint.com/understanding-module-exports-exports-node-js/
Subscribe to:
Posts (Atom)
