To test if the current script has been executed as the main input to the program check import.meta.main.
import.meta.main
if (import.meta.main) { console.log("main"); }