https://github.com/rumkin/npx-esm
Run ESM programs with Node.js’ NPX util
https://github.com/rumkin/npx-esm
Last synced: about 1 year ago
JSON representation
Run ESM programs with Node.js’ NPX util
- Host: GitHub
- URL: https://github.com/rumkin/npx-esm
- Owner: rumkin
- Created: 2020-06-10T22:19:14.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-07-05T08:06:58.000Z (almost 6 years ago)
- Last Synced: 2025-03-18T10:48:33.665Z (about 1 year ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
# NPX ESM
Run ESM modules as node programs with npx in a three steps.
1. Install `npx-esm` package:
```shell
npm install -D npx-esm
```
2. Create program `index.js`:
```js
export default function() {
console.log('Hello')
}
```
3. Execute it:
```shell
npx esm index.js
```
## API
### `CmdParams`
```text
{
argv: Array,
argvHead: Array,
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
```js
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](https://rumk.in)