Skip to content

Instantly share code, notes, and snippets.

@philipisapain
Last active March 7, 2018 14:03
Show Gist options
  • Save philipisapain/426e92b39ad7c28f769fe9d28bbf7ae3 to your computer and use it in GitHub Desktop.
Save philipisapain/426e92b39ad7c28f769fe9d28bbf7ae3 to your computer and use it in GitHub Desktop.
Example of optionally exporting a module
const SomeDependency = require('some-dependency')
class TopLevelProcess {
constructor (someDependency) { ... }
start () { ... }
}
const isNodeProcess = require.main === module
if (isNodeProcess) {
new TopLevelProcess(new SomeDependency()).start()
} else {
module.exports = { TopLevelProcess }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment