title: How to extend Node classes for abstraction purposes within Cypress?
body: <p><strong>Goal</strong>: Create a URL abstraction for our specific product by extending Node's URL class within a Cypress project.</p>
  <p><strong>Problem</strong>: Cypress executes everything within a browser context, so you can only use node modules in the plugins file which executes within a Node environment. However, I don't really need to <em>execute</em> anything, I just want to extend the available Node objects so I don't have to reimplement these abstractions myself.</p>
  <p>I get the following error in Cypress when I set the <code>baseUrl</code> to <code>new ProductURL().toString()</code>:</p>
  <p><a href="https://i.stack.imgur.com/bhssN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bhssN.png" alt="enter image description here" /></a></p>
  <p>Code:</p>
  <pre class="lang-js prettyprint-override"><code>import { URL } from 'url';
  
  export class ProductURL extends URL {
      static readonly DEFAULT_URL: string = &quot;https://example.com&quot;;
      static readonly DEFAULT_AUTH: BasicAuthCredentials = {
          username: Cypress.env('BASIC_AUTH_USERNAME'),
          password: Cypress.env('BASIC_AUTH_PASSWORD')
      }
  
      private domain: string;
      private subdomain: string;
  
      constructor() {
          super(ProductURL.DEFAULT_URL);
          this.setAuth(ProductURL.DEFAULT_AUTH);
      }
  
      public getDomain(): string {
          return this.domain;
      }
  
      public getSubdomain(): string {
          return this.subdomain;
      }
  
      public setPort(port: number) {
          this.port = String(port);
      }
  
      public setProtocol(protocol: Protocol) {
          this.protocol = protocol;
      }
  
      public setAuth(auth: BasicAuthCredentials | null) {
          this.username = auth ? auth.username : '';
          this.password = auth ? auth.password : '';
      }
  }
  
  export enum Protocol {
      HTTP = &quot;http&quot;,
      HTTPS = &quot;https&quot;
  }
  
  export type BasicAuthCredentials = {
      username: string;
      password: string;
  };
  
  </code></pre>
  <p><strong>Question</strong>: How can I extend Node classes for abstraction purposes within Cypress context?</p>