title: Discord.js in an Express RESTful API
body: <p>I am trying to use the <a href="https://discord.js.org" rel="nofollow noreferrer">Discord.js</a> library in an Express RESTful API. I'm wondering how I should share the client between controllers, because the client is initialized asynchronously and apparently it is bad practice to call <code>client.login(...)</code> multiple times. In other words, I have an asynchronous initialization method that I cannot call multiple times and I need to access this client across multiple controllers. Here's what I'm doing right now:</p>
  <p><strong><code>discord.helper.js</code></strong></p>
  <pre class="lang-js prettyprint-override"><code>const Discord = require('discord.js');
  
  const client = new Discord.Client();
  client.login(process.env.DISCORD_BOT_TOKEN);
  
  export default client;
  </code></pre>
  <p>My issue is that because the <code>client.login()</code> is asynchronous but can <em>only be called one time</em>, I cannot import this file with the assumption that the bot has already been initialized. Any ideas on how I should structure this module so that I can import it multiple times with the assumption that it has already been initialized?</p>