Last active
October 10, 2016 12:02
-
-
Save jsynowiec/5a7e65c01f7fa4b96f24fcb44a946e9f to your computer and use it in GitHub Desktop.
Detect if a module has been run directly from Node.js or imported, read more: https://nodejs.org/api/modules.html#modules_accessing_the_main_module
This file contains 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 dgram = require('dgram'); | |
let server = dgram.createSocket('udp4'); | |
function bind(socket, port = 8088, address = '0.0.0.0', callback = () => {}) { | |
socket.bind(port, address, callback); | |
} | |
// Bind server only if module was run directly, eg. node server.js | |
if (require.main === module) { | |
bind(server, process.env.PORT, process.env.HOST); | |
} | |
module.exports = { | |
server, | |
bind | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment