node cjs-module.js
node --esm es-module.js
Or introduce other binary:
nodejs es-module.js
(Possibly with some major Node.js version ES module could start being default)
| // Import CJS module | |
| const otherCJSModule = require('./other-cjs-module'); | |
| // Import ES module, relying on upcoming standard | |
| import('./es-module').then(function (esModule) { | |
| ... | |
| }); | |
| // Import core module | |
| const fs = require('fs'); |
| // Import ES module | |
| import * from './other-es-module'; | |
| // Import CJS module | |
| // This may need to look a bit different, as 'require' is expected to be different function | |
| // in each module that imports it | |
| import { require } from 'nodejs'; | |
| const cjsModule = require('./cjs-module'); | |
| // Import core module | |
| import fs from 'fs'; |