Skip to content

Instantly share code, notes, and snippets.

@rm-rf-etc
Last active December 26, 2019 06:38
Show Gist options
  • Save rm-rf-etc/ded65ccf885e256df419bef799ed5809 to your computer and use it in GitHub Desktop.
Save rm-rf-etc/ded65ccf885e256df419bef799ed5809 to your computer and use it in GitHub Desktop.
Basics of using ES Modules
export const add = (a, b) => a + b;
export const subtract = (a, b) => a - b;
export default { add, subtract };
import mainModule, { add, subtract } from "./includes.js";
console.log(add(1, 2));
// 3
console.log(mainModule.add(1, 2));
// 3
console.log(subtract(1, 2));
// -1
console.log(mainModule.subtract(1, 2));
// -1
npm init -y
npm install --save-dev esm
node -r esm index.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment