Last active
March 7, 2018 14:03
-
-
Save philipisapain/426e92b39ad7c28f769fe9d28bbf7ae3 to your computer and use it in GitHub Desktop.
Example of optionally exporting a module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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