Node.js counterpart of Python's __name__ == __main__

Determine whether a module has been run directly

The following programs are roughly equivalent:

Python

Works in the REPL.

def run():
    print('hello, world')


if __name__ == '__main__':
    run()

JavaScript of the Node.js variety

Doesn't work in the REPL.

function run() {
    console.log('hello, world')
}

if (require.main === module) {
    run()
}

Docs