is-main
TypeScript icon, indicating that this package has built-in type declarations

0.4.0 • Public • Published

is-main

Check if current module is main module.

Installation

npm install is-main --save

Usage

import { isMain } from 'is-main'

if (isMain(import.meta)) {
  console.log('is main')
}
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 for more information.

Related

  • esmeta - Handy function to handle import.meta

Package Sidebar

Install

npm i is-main

Weekly Downloads

6

Version

0.4.0

License

MIT

Unpacked Size

8 kB

Total Files

10

Last publish

Collaborators

  • ratson