Bun Check if the current file is the entrypoint

Check if the current file is the entrypoint

jarle Updated

File contents

Check if the current file is the entrypoint

Bun provides a handful of module-specific utilities on the import.meta object. Use import.meta.main to check if the current file is the entrypoint of the current process.

if (import.meta.main) {
  // this file is directly executed with `bun run`
} else {
  // this file is being imported by another file
}

See Docs > API > import.meta for complete documentation.

jarle/bun-skills/tree/main/skills/bun-guides-util-entrypoint commit 79ec463c6c

Frequently asked questions

npx skillmds@latest add jarle/bun-check-if-the-current-file-is-the-entrypoint