Correct async function export in node.js : <p>I had my custom module with following code:</p>

<pre><code>module.exports.PrintNearestStore = async function PrintNearestStore(session, lat, lon) {
...
}
</code></pre>

<p>It worked fine if call the function outside my module, however if I called inside I got error while running:</p>

<blockquote>
  <p>(node:24372) UnhandledPromiseRejectionWarning: Unhandled promise
  rejection (rejection id: 1): ReferenceError: PrintNearestStore is not
  defined</p>
</blockquote>

<p>When I changed syntax to:</p>

<pre><code>module.exports.PrintNearestStore = PrintNearestStore;

var PrintNearestStore = async function(session, lat, lon) {

}
</code></pre>

<p>It started to work fine inside module, but fails outside the module - I got error:</p>

<blockquote>
  <p>(node:32422) UnhandledPromiseRejectionWarning: Unhandled promise
  rejection (rejection id: 1): TypeError: mymodule.PrintNearestStore is
  not a function</p>
</blockquote>

<p>So I've changed code to:</p>

<pre><code>module.exports.PrintNearestStore = async function(session, lat, lon) {
    await PrintNearestStore(session, lat, lon);
}

var PrintNearestStore = async function(session, lat, lon) {
...
}
</code></pre>

<p>And now it works in all cases: inside and outside. However want to understand semantics and if there is more beautiful and shorter way to write it? How to correctly  define and use <strong>async</strong> function both: inside and outside (exports) module?</p>
