nephets nephets - 1 year ago 59
Javascript Question

Exit from loading Node module early without stopping process

I have a module which gets

, but I temporarily don't want to run the code in the module. I could just comment it out, but then it got me wondering if there is a way to exit/return early from a loading module.

Is there a built in way to stop the execution flow through the module's code, and "return" early?

Answer Source

There isn't a build-in way, but you can use the following workaround. Wrap the whole module in an IIFE and just use return statement:

(function() {

  // some code

  // stop execution here

  // some code