main
true
when the current module is the entry point of the current process; false
otherwise.
Equivalent to require.main === module
in CommonJS.
Analogous to Python's __name__ == "__main__"
.
export function foo() {
return 'Hello, world';
}
function main() {
const message = foo();
console.log(message);
}
if (import.meta.main) main();
// `foo` can be imported from another module without possible side-effects from `main`
Content copied to clipboard
Since
v24.2.0