CommonJS
키워드. NodeJS가 채택CommonJS: 자바스크립트 언어의 활동 영역을 확장하기 위해 조직된 그룹
require : 가져오기
exports : 내보내기
module.exports : 내보내기
module.exports 객체에 모듈 전체를 내보내고 require
를 통해 모듈을 불러오는 방식 → 불필요한 모듈 로드 가능성
import : 가져오기
export : 내보내기
export defaults : 내보내기
require
에 비해 성능 우수, 메모리 절약const example = require("example");
// 외부 파일이나 라이브러리를 불러오는 작업을 수행하는 것은 동일
import example from "example";
// import 키워드 사용하여 명시적으로 모듈을 불러옴
require
사용Babel
: ES6코드 변환 도구const arr = [1,2,3]
arr.pop()
arr[1] = 5 // [1,5]