Skip to content Skip to sidebar Skip to footer

How To Have A Commonjs Module Execute Its Main() (as In Python)?

I wonder if a method exists that would run a predefined function in a CommonJS module (as those used in Node.js). I wrote a couple of node modules that act as services/servers. I c

Solution 1:

if (require.main === module) {
    console.log("running standalone");
}

accessing the main module


Post a Comment for "How To Have A Commonjs Module Execute Its Main() (as In Python)?"