2.4.0 • Published 5 years ago

@nore/esm v2.4.0

Weekly downloads
1
License
ISC
Repository
github
Last release
5 years ago

@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/esm

API

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

License ISC  ·  GitHub @ugin  ·  Twitter @navaru

2.4.0

5 years ago

2.3.0

5 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.2.0

6 years ago

1.1.2

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago