🔰import .js file

const { log } = console;

// ⭐ use "require", not "import" (in Node)
const utils = require('./utils.js');

log(utils.power);         // 9001
log(utils.square(5));     // 25

// ⭐ can also do the same thing like so:
const {power, square} = require('./utils.js');

log(power);               // 9001
log(square(5));           // 25

📁 utils.js

module.exports = {
    power: 9001,
    square: x => x*x
};

Last updated