Script And Friends logo

Modules 03


// file-1.js
  const sum = (x, y) = > x + y;
  const square = x = > x * x;
  const mean = data = > data.reduce( sum)/ data.length;
  module.exports = { sum, square };

Let us assume that there is a file file-2.js in the same directory as file-1.js. Import the function sum from file-1.js into file-2.js by using the native node.js syntax (also known as the CommonJS syntax).