a.js
export const A = ‘A‘;
index.js
import { A } from ‘./a.js‘;
console.log(A);
{ "type": "module" }
$ node index.js
其他方法参考 https://nodejs.org/api/esm.html
在 Node.js 中使用 ES6 模块 import 和 export
原文:https://www.cnblogs.com/wenruo/p/12928950.html