Skip to content

Idiomatic way of checking if is main script (require.main === module in cjs/node) #8884

Answered by alexeyten
rhyek asked this question in Q&A
Discussion options

You must be logged in to vote

Is import.meta.main what you want?

https://bun.sh/docs/api/import-meta

if (import.meta.main) {
  console.log('is main');
} else {
  console.log('is not main ');
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@rhyek
Comment options

Answer selected by rhyek
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants