https://github.com/ratson/is-main
Check if current module is main module.
https://github.com/ratson/is-main
esm esmodules main main-module require-main
Last synced: 5 months ago
JSON representation
Check if current module is main module.
- Host: GitHub
- URL: https://github.com/ratson/is-main
- Owner: ratson
- Created: 2018-04-09T15:41:51.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-01-30T18:17:16.000Z (about 3 years ago)
- Last Synced: 2025-06-27T02:18:14.078Z (8 months ago)
- Topics: esm, esmodules, main, main-module, require-main
- Language: TypeScript
- Size: 26.4 KB
- Stars: 5
- Watchers: 1
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# is-main
Check if current module is main module.
## Installation
```
npm install is-main --save
```
## Usage
```js
import { isMain } from 'is-main'
if (isMain(import.meta)) {
console.log('is main')
}
```
```js
const { isMain } = require('is-main')
if (isMain(module)) {
console.log('is main')
}
```
## Note
While it is useful to put main script with the module code in the same file,
move main script into a separate file is often better,
given there is no standard way for detecting main script.
See this [Node issue](https://github.com/nodejs/node/issues/15760) for more information.
## Related
- [esmeta](https://github.com/ratson/esmeta) - Handy function to handle import.meta