npm-use 폴더 안에 index.js와 index.mjs 파일을 생성합니다.
index.js
const npmtest = require('npmtest-1234');
console.log(npmtest());
index.mjs
import npmtest from 'npmtest-1234';
console.log(npmtest());
콘솔
$ node index
hello commonjs module
$ node index.mjs
hello es module
npmtest의 package.json exports 속성에 적힌 대로 require를 하면 출시한 패키지의 index.js를 불러오고, import를 하면 출시한 패키지의 index.mjs를 불러옵니다. 이렇게 CommonJS 모듈과 ES 모듈에 둘 다 대응해서 배포하면 두 모듈 방식의 사용자에게 모두 편의를 제공할 수 있습니다.