@nore/esm
Allows the use of import and export syntax in node.js.
Under the hood it wraps node's loading mechanism, parses all required files, converting ES Modules syntax to node's syntax (CJS).
Installation
$ npm install @nore/esmAPI
Relative imports to source's path (~/path)
This module also handles relative paths to the project's source folder: ~/path/to/file.js. By default it resolves the ~ to process.cwd(), this can be overwritten by setting the path on ES_SOURCE_PATH (environment variable).
import accounts from "~/services/accounts"@nore/esm/register
Convert ES Modules to CommonJS on runtime:
// read.js
import { readFile } from 'fs'
export default (path, handler) => {
readFile(path, 'utf8', handler)
}// index.js
require("@nore/esm/register");
const read = require("./read.js");es CLI command
Run ES Modules files:
// passwords.js
import { readFileSync } from 'fs'
console.log(readFileSync('/etc/passwd', 'utf8')) ▸ es passwords.js