JavaScript 방식으로 export 하는 방법

  1. npm init -y 으로 package.json 파일을 생성
  2. "type": "module" 을 작성
{
  "name": "5_module",
  "version": "1.0.0",
  "description": "",
  "main": "app.js",
  "type": "module",
  "scripts": {
    "test": "echo \\"Error: no test specified\\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
// count.js
let count = 0;

export function increase() {
  count++;
}

export function getCount() {
  return count;
}

JavaScript 방식으로 import 하는 방법

// app.js
import { increase, getCount } from './count.js';

increase();
increase();
increase();
console.log(getCount());