Node.js에서 사용할 수 있는 module system:
- Importing modules using
require
, and exporting usingmodule.exports
and exports.foo - Importing modules using ES6
import
, and exporting using ES6export
.
그럼 둘 간의 차이는?
require()
from NodeJS (CommonJS)
- dynamic loading을 할 수 있다.
- synchronous (여러 개를 require하면 순차적으로 처리)
import
from ES6
- named import를 사용할 수 있고, import하는 대상을 온전히 로딩하는게 아니고, 그 중 필요한 부분만 destructuring처럼 가져올 수 있어서 메모리에 장점
- asynchronous
현재는 Babel을 통해서 import/export를 사용하는데 이것들은 기본적으로 CommonJS (require/module.exports) 로 transpiling되기 때문에 CommonJS방식을 사용하는 것도 문제가 되진 않겠다.
참고 출처: http://researchhubs.com/post/computing/javascript/nodejs-require-vs-es6-import-export.html
'Coding' 카테고리의 다른 글
nodejs backend 개발을 할때 nodemon, process manager...? (0) | 2017.07.07 |
---|---|
create-react-app에서 알아두면 좋을 것들 (0) | 2017.07.06 |
default export와 named export의 차이 (0) | 2017.07.05 |
Node 8 그리고 npm 5 (0) | 2017.06.16 |
@SpringBootTest, @WebMvcTest 차이 (0) | 2017.06.15 |