npx-esm

1.3.0 • Public • Published

NPX ESM

Run ESM modules as node programs with npx in a three steps.

  1. Install npx-esm package:
npm install -D npx-esm
  1. Create program index.js:
export default function() {
  console.log('Hello')
}
  1. Execute it:
npx esm index.js

API

CmdParams

{
  argv: Array<string>,
  argvHead: Array<string>,
  cwd: string,
  stdin: ReadableStream,
  stdout: WritableStream,
  stderr: WriteableStream,
}

The main function receives a command params as the first argument. It contains minimal set of params to execute a command and interact with the user or pipeline.

  • argv is the list of command line arguments remained after removing executable adn script paths.
  • argvHead is the list of command line arguments cropped as executable and script paths.
  • cwd is the current directory.
  • stdin, stdout and stderr are I/O streams.

Example

async function main({
  argv, // -> ['--help']
  argvHead, // -> ['node', 'script.js']
  cwd, // '/dev/project/esm'
  stdout, // writable stream
  stderr, // writable stream
  stdin, // readable stream
}) {
  stdout.write('OK')
  return 1
}

License

MIT © Rumkin

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.3.0
    5
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.3.0
    5
  • 1.2.0
    0
  • 1.1.0
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i npx-esm

Weekly Downloads

5

Version

1.3.0

License

MIT

Unpacked Size

3.19 kB

Total Files

6

Last publish

Collaborators

  • rumkin