Last active
December 26, 2019 06:38
-
-
Save rm-rf-etc/ded65ccf885e256df419bef799ed5809 to your computer and use it in GitHub Desktop.
Basics of using ES Modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const add = (a, b) => a + b; | |
export const subtract = (a, b) => a - b; | |
export default { add, subtract }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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