# subprogram

> Turn individual ES modules into subprograms that can be run with node or improted without running.

Latest version **1.3.0** (published 2022-06-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install subprogram
pnpm add subprogram
yarn add subprogram
bun add subprogram
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.3.0 |
| Published | 2022-06-24 |
| First published | 2021-07-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 28.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Irakli Gozalishvili |
| Maintainers | gozala |
| Keywords | main, program, ESM, module, scirpt |

## Links

- npm: https://www.npmjs.com/package/subprogram
- Repository: https://github.com/gozala/subprogram
- Homepage: https://github.com/gozala/subprogram#readme
- Issues: https://github.com/gozala/subprogram/issues
- npm.io page: https://npm.io/package/subprogram

## Dependencies (1)

- [dotenv](https://npm.io/package/dotenv.md) ^10.0.0

## Recent versions

- 1.3.0 (latest) — 2022-06-24
- 1.2.0 — 2021-07-08
- 1.1.0 — 2021-07-02
- 1.0.2 — 2021-07-02
- 1.0.1 — 2021-07-02
- 1.0.0 — 2021-07-02
- 0.0.0 — 2021-07-02

## README

# subprogram

Utility to turn individual ES modules into programs that can be run.

### Usage

You can turn ES module into runnable node program. This is an ES alternative to `if (require.main === module) { ... }` pattern.

```js
import { script } from "subprogram"

export const main () => {
  console.log("Hello world")
}

script({ ...import.meta, main })
```

When above program is run as `node script.js` it will run a `main` function of the module, if module is imported no action will take place.

---
_Source: https://npm.io/package/subprogram · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
