title: How to properly load JQuery Objects from Node Modules?
body: <p>I am working on the simple NodeJs App. While working with Frontend, it correctly loads all NodeJS modules related to JQuery, but when I am going to make a simple JavaScript-based Implementation and trying to load all of those JQuery files from Node-Modules. I am unable to get anything out of them.</p>
  <p>I am really new to NodeJS and JQuery, but I am passionate to develop a console-based Implementation for my testing.</p>
  <hr />
  <p><strong>Node-Modules:</strong></p>
  <p>Following are the node modules on which I am working right now.</p>
  <pre><code>  &quot;dependencies&quot;: {
  &quot;crypto-js&quot;: &quot;^3.1.9-1&quot;,
  &quot;jquery&quot;: &quot;^3.6.0&quot;,
  &quot;jquery-json&quot;: &quot;^2.6.0&quot;,
  &quot;verto&quot;: &quot;0.0.2&quot;
  }
  </code></pre>
  <hr />
  <p><strong>Working Example:</strong></p>
  <p>I have implemented the following files to work with these modules;</p>
  <ul>
  <li>index.html</li>
  <li>app.js</li>
  </ul>
  <p><strong>index.html</strong></p>
  <pre><code>
  &lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset=&quot;utf-8&quot;&gt;
      &lt;title&gt;Demo of Aswat Verto Integration&lt;/title&gt;
      &lt;link rel=&quot;stylesheet&quot; href=&quot;app.css&quot;&gt;
    &lt;/head&gt;
  
    &lt;body&gt;
      &lt;div class=&quot;config&quot;&gt;
        &lt;div class=&quot;config-row&quot;&gt;
          &lt;label for=&quot;hostname&quot;&gt;Hostname&lt;/label&gt;
          &lt;input id=&quot;hostname&quot; type=&quot;text&quot;&gt;
        &lt;/div&gt;
        &lt;div class=&quot;config-row&quot;&gt;
          &lt;label for=&quot;socketURL&quot;&gt;Socket URL&lt;/label&gt;
          &lt;input id=&quot;socketURL&quot; type=&quot;text&quot;&gt;
        &lt;/div&gt;
        &lt;div class=&quot;config-row&quot;&gt;
          &lt;label for=&quot;position&quot;&gt;Position&lt;/label&gt;
          &lt;input id=&quot;position&quot; type=&quot;text&quot;&gt;
        &lt;/div&gt;
        &lt;div class=&quot;config-row&quot;&gt;
          &lt;label for=&quot;password&quot;&gt;Password&lt;/label&gt;
          &lt;input id=&quot;password&quot; type=&quot;text&quot;&gt;
        &lt;/div&gt;
        &lt;div class=&quot;config-row&quot;&gt;
          &lt;button class=&quot;config-action&quot; onclick=&quot;connectToFreeswitch()&quot;&gt;Connect&lt;/button&gt;
        &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class=&quot;dialler&quot;&gt;
        &lt;div class=&quot;dialler-status&quot;&gt;
          Current status &lt;br&gt;
          &lt;span id=&quot;positionStatus&quot;&gt;Not Connected&lt;/span&gt; &lt;br&gt; &lt;span id=&quot;callStatus&quot;&gt;Not in a Call&lt;/span&gt;
        &lt;/div&gt;
        &lt;div class=&quot;dialler-content&quot; id=&quot;dialler&quot;&gt;
          &lt;div class=&quot;dialler-row&quot;&gt;
            &lt;input type=&quot;text&quot; class=&quot;dialler-input&quot; id=&quot;diallerInput&quot;&gt;
          &lt;/div&gt;
  
          &lt;div class=&quot;dialler-row&quot;&gt;
            &lt;span class=&quot;dialler-number&quot; onclick=&quot;dial('1')&quot;&gt;1&lt;/span&gt;
            &lt;span class=&quot;dialler-number&quot; onclick=&quot;dial('2')&quot;&gt;2&lt;/span&gt;
            &lt;span class=&quot;dialler-number&quot; onclick=&quot;dial('3')&quot;&gt;3&lt;/span&gt;
          &lt;/div&gt;
  
          &lt;div class=&quot;dialler-row&quot;&gt;
            &lt;span class=&quot;dialler-number&quot; onclick=&quot;dial('4')&quot;&gt;4&lt;/span&gt;
            &lt;span class=&quot;dialler-number&quot; onclick=&quot;dial('5')&quot;&gt;5&lt;/span&gt;
            &lt;span class=&quot;dialler-number&quot; onclick=&quot;dial('6')&quot;&gt;6&lt;/span&gt;
          &lt;/div&gt;
  
          &lt;div class=&quot;dialler-row&quot;&gt;
            &lt;span class=&quot;dialler-number&quot; onclick=&quot;dial('7')&quot;&gt;7&lt;/span&gt;
            &lt;span class=&quot;dialler-number&quot; onclick=&quot;dial('8')&quot;&gt;8&lt;/span&gt;
            &lt;span class=&quot;dialler-number&quot; onclick=&quot;dial('9')&quot;&gt;9&lt;/span&gt;
          &lt;/div&gt;
  
          &lt;div class=&quot;dialler-row&quot;&gt;
            &lt;span class=&quot;dialler-number&quot; onclick=&quot;dial('*')&quot;&gt;*&lt;/span&gt;
            &lt;span class=&quot;dialler-number&quot; onclick=&quot;dial('0')&quot;&gt;0&lt;/span&gt;
            &lt;span class=&quot;dialler-number&quot; onclick=&quot;dial('#')&quot;&gt;#&lt;/span&gt;
          &lt;/div&gt;
  
          &lt;div class=&quot;dialler-row&quot;&gt;
            &lt;button class=&quot;dialler-action&quot; onclick=&quot;makeCall()&quot;&gt;Call&lt;/button&gt;
            &lt;button class=&quot;dialler-action&quot; onclick=&quot;hangupCall()&quot;&gt;Hangup&lt;/button&gt;
          &lt;/div&gt;
  
          &lt;div class=&quot;dialler-row&quot;&gt;
            &lt;button class=&quot;dialler-action&quot; onclick=&quot;answerCall()&quot;&gt;Answer&lt;/button&gt;
            &lt;button class=&quot;dialler-action&quot; onclick=&quot;transfer()&quot;&gt;Transfer&lt;/button&gt;
          &lt;/div&gt;
  
          &lt;div class=&quot;dialler-row&quot;&gt;
            &lt;button class=&quot;dialler-action&quot; onclick=&quot;mute()&quot;&gt;Mute&lt;/button&gt;
            &lt;button class=&quot;dialler-action&quot; onclick=&quot;unmute()&quot;&gt;Unmute&lt;/button&gt;
          &lt;/div&gt;
  
          &lt;div class=&quot;dialler-row&quot;&gt;
            &lt;button class=&quot;dialler-action&quot; onclick=&quot;hold()&quot;&gt;Hold&lt;/button&gt;
            &lt;button class=&quot;dialler-action&quot; onclick=&quot;unhold()&quot;&gt;Unhold&lt;/button&gt;
          &lt;/div&gt;
        &lt;/div&gt;
  
        &lt;video class=&quot;hide&quot; id=&quot;positionDevice&quot; autoplay=&quot;autoplay&quot; style=&quot;width:100%; height:100%; object-fit:inherit;&quot;&gt;&lt;/video&gt;
      &lt;/div&gt;
  
      &lt;!-- Verto dependencies --&gt;
      &lt;script src=&quot;../node_modules/jquery/dist/jquery.min.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;../node_modules/jquery-json/dist/jquery.json.min.js&quot;&gt;&lt;/script&gt;
  
      &lt;!-- Verto library --&gt;
      &lt;script src=&quot;../node_modules/verto/src/jquery.verto.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;../node_modules/verto/src/jquery.FSRTC.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;../node_modules/verto/src/jquery.jsonrpcclient.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;app.js&quot;&gt;&lt;/script&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  
  </code></pre>
  <p><strong>app.js</strong></p>
  <pre><code>
  let diallerInput = document.getElementById('diallerInput');
  let currentCall = '';
  
  /**
    This function will execute the _bootstrap function to connect to the Verto server
    and log in with specified credentials and configurations.
    To see the full documentation, go to: http://evoluxbr.github.io/verto-docs/tut/initializing-verto.html
  **/
  function connectToFreeswitch() {
    hostname  = document.getElementById('hostname').value;
    socketURL = document.getElementById('socketURL').value;
    position  = document.getElementById('position').value;
    password  = document.getElementById('password').value;
  
    function _bootstrap(status) {
      vertoHandle = new jQuery.verto({
        login: position + '@' + hostname,
        passwd: password,
        socketUrl: socketURL,
        ringFile: 'ringtone.mp3',
        tag: 'positionDevice',
        deviceParams: {
          useMic: true,
          useSpeak: true
        },
        iceServers: true
      },
      /**
        Almost everything that happens in Verto fires an event.
        onWSLogin will be fired on login
        onWSClose will be fired when closing the socket
        onDialogState is used to handle incoming and outgoind calls
      **/
      {
        onWSLogin: onWSLogin,
        onWSClose: onWSClose,
        onDialogState: onDialogState
      });
    }
  
    if (hostname &amp;&amp; socketURL &amp;&amp; position &amp;&amp; password) $.verto.init({}, _bootstrap);
    else alert('You need to provide the full configuration settings.');
  }
  
  
  </code></pre>
  <p>Using the above files, NodeJs Modules related to these JQuery Files are properly loading into Dom Object;</p>
  <pre><code>    &lt;!-- Verto dependencies --&gt;
      &lt;script src=&quot;../node_modules/jquery/dist/jquery.min.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;../node_modules/jquery-json/dist/jquery.json.min.js&quot;&gt;&lt;/script&gt;
  
      &lt;!-- Verto library --&gt;
      &lt;script src=&quot;../node_modules/verto/src/jquery.verto.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;../node_modules/verto/src/jquery.FSRTC.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;../node_modules/verto/src/jquery.jsonrpcclient.js&quot;&gt;&lt;/script&gt;
  
  </code></pre>
  <p>I have tested it with the front-end, and everything is going really great; But What I need is to load the above given node modules, directly into JS.</p>
  <hr />
  <p><strong>Not Working Example:</strong></p>
  <p>Here I have implemented this technique to load JQuery Objects;</p>
  <p><strong>verto.html</strong></p>
  <pre><code>&lt;!doctype html&gt;
  &lt;html&gt;
    &lt;head&gt;
      &lt;meta charset=&quot;UTF-8&quot;&gt;
      &lt;title&gt;&lt;/title&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;script src=&quot;./node_modules/jquery/dist/jquery.min.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;./node_modules/jquery-json/dist/jquery.json.min.js&quot;&gt;&lt;/script&gt;
  
      &lt;script src=&quot;./node_modules/verto/src/jquery.verto.js&quot;&gt;&lt;/script&gt;
      &lt;script src=&quot;./node_modules/verto/src/jquery.FSRTC.js&quot;&gt;&lt;/script&gt;  &lt;/body&gt;
  &lt;/html&gt;
  
  </code></pre>
  <p><strong>app.js</strong></p>
  <pre><code>
  'use strict';
  
  const { JSDOM } = require('jsdom');
  
  const options = {
    resources: 'usable',
    runScripts: 'dangerously',
  };
  
  JSDOM.fromFile('verto.html', options).then((dom) =&gt; {
    console.log(dom.window.document.body.textContent.trim());
    
    // Importing the jquery and providing it
    // with the window
    const jquery = require(&quot;jquery&quot;)(dom.window);
    console.log(jquery);
    console.log(jquery.verto);
  
  
    setTimeout(() =&gt; {
      console.log(dom.window.document.body.textContent.trim());
    }, 5000);
  });
  
  </code></pre>
  <p>When I run this simple app, it's not loading simple JQuery at all. I need assistance regarding the above problem; I have visited these articles but I am not sure where I am doing wrong;</p>
  <ul>
  <li><a href="https://www.geeksforgeeks.org/how-to-use-jquery-with-node-js/" rel="nofollow noreferrer">How to use jQuery with Node.js ? - GeeksforGeeks</a></li>
  <li><a href="https://stackoverflow.com/a/53236877">How to load local JavaScript file with JSDOM?</a></li>
  </ul>
  <p>Your little assistance might save my whole day; Thanks in Advance</p>