# is-launch-file

> Determine if a file was called directly with NodeJS Modules.

Latest version **1.0.3** (published 2020-11-22) · MIT license · 0 weekly downloads

## Install

```sh
npm install is-launch-file
pnpm add is-launch-file
yarn add is-launch-file
bun add is-launch-file
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.3 |
| Published | 2020-11-22 |
| First published | 2020-11-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 2.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Maintainers | seveibar |

## Links

- npm: https://www.npmjs.com/package/is-launch-file
- Repository: https://github.com/seveibar/is-launch-file
- Homepage: https://github.com/seveibar/is-launch-file#readme
- Issues: https://github.com/seveibar/is-launch-file/issues
- npm.io page: https://npm.io/package/is-launch-file

## Recent versions

- 1.0.3 (latest) — 2020-11-22
- 1.0.2 — 2020-11-22
- 1.0.1 — 2020-11-22
- 1.0.0 — 2020-11-22

## README

# isLaunchFile: Determine if a file was called directly with NodeJS Modules

Determine if a file was called directly with NodeJS Modules.

In NodeJS packages with `"type": "module"`, the `module` and `require` keywords are undefined, so you can't use the old method of `if (!module.parent)`. `isLaunchFile`
uses `import.meta.url` and `process.argv[0]` to determine if a file was called directly.

## Installation

```bash
npm install --save is-launch-file
```

## Usage

```javascript
import isLaunchFile from "is-launch-file"

if (isLaunchFile(import.meta.url)) {
	// This file was called directly.
}
```

## Example

```javascript
// ------------------------
// call-me-directly.js
// ------------------------
import isLaunchFile from "../index.js"
import "./only-imported.js"

console.log("call-me-directly.js:", isLaunchFile(import.meta.url))

// ------------------------
// only-imported.js
// ------------------------
import isLaunchFile from "../index.js"

console.log("only-imported.js:", isLaunchFile(import.meta.url))
```

If you execute `node call-me-directly.js`, you'll get the
following output:

```
call-me-directly.js: true
only-imported.js: false
```

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