title: Getting Error 'Error: Unable to load PFX certificate' on a Node Js application while connecting to ElasticSearch
body: <p>I am getting the below error stack trace while querying the elastic from NodeJs app.</p>
  <pre><code>Error: Unable to load PFX certificate
  at configSecureContext (node:internal/tls:304:15)
  at Object.createSecureContext (node:_tls_common:113:3)
  at Object.connect (node:_tls_wrap:1619:48)
  at HttpsAgent.createConnection (node:https:136:22)
  at HttpsAgent.createSocket (/Users/arshpreetsingh/Desktop/Desktop – MacBook Pro/Diagnotics Services/diagnostic-search/node_modules/agentkeepalive/lib/_http_agent.js:265:26)
  at HttpsAgent.createSocket (/Users/arshpreetsingh/Desktop/Desktop – MacBook Pro/Diagnotics Services/diagnostic-search/node_modules/agentkeepalive/lib/agent.js:77:11)
  at HttpsAgent.addRequest (/Users/arshpreetsingh/Desktop/Desktop – MacBook Pro/Diagnotics Services/diagnostic-search/node_modules/agentkeepalive/lib/_http_agent.js:239:10)
  at new ClientRequest (node:_http_client:305:16)
  at Object.request (node:https:317:10)
  at Object.request (/Users/arshpreetsingh/Desktop/Desktop – MacBook Pro/Diagnotics Services/diagnostic-search/node_modules/agent-base/patch-core.js:25:22)
  </code></pre>
  <p>My elastc client looks like this.</p>
  <pre><code>import elasticsearch from 'elasticsearch';
  import CONFIG from '../config/index';
  
  const elasticClient = new elasticsearch.Client({
  host: CONFIG.es_url,
  });
  
  
   export default {
      search: async (...args) =&gt; {
      try {
          return await elasticClient.search(...args)
      } catch (error) {
          if (error.status == 400) {
              return { hits: { total: 0 } }
          }
          throw error
      }
  }
  </code></pre>
  <p>}</p>
  <p>The URL of the elastic search starts with https.</p>