OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How do I solve this net::ERR_ABORTED 404 (Not Found) error when programming a web app using Javascript and Node.js

  • Thread starter Thread starter AREemEHS
  • Start date Start date
A

AREemEHS

Guest
I am trying to write code in JavaScript (Node.js) that will take stock market data and analyze it using an LLM (langchain in particular). My code is below:

Code:
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Financial Data Lookup</title>
  <style>
    .myDiv {
      position: absolute;
      transform: translate(-50%, -75%);
      top: 250px;
      left: 50%;
      width: 500px;
      border: 10px outset lime;
      background-color: blue;
      text-align: center;
    }
    table, th, td {
      border: 1px solid;
      width: 500px;
    }
  </style>
</head>
<body>

<div class="myDiv" id="myDiv">
  <h1 class="white-text" style="color: white;">Input Stock Ticker</h1>
  <input type="text" id="myName" placeholder="ex. AAPL">
  <button id="btn">Compile</button>
</div>

<div class="StockDataTable" id="StockDataTable" style="z-index: 2; position: absolute; top: 400px;">
  <table style="margin-left:300px;">
    <thead>
      <tr>
        <th colspan="2">Basic Financials</th>
      </tr>
    </thead>
    <tbody>
      <tr><td>Cash Ratio:</td><td id="c2r2"></td></tr>
      <tr><td>Current Ratio:</td><td id="c2r3"></td></tr>
      <tr><td>EBIT Per Share:</td><td id="c2r4"></td></tr>
      <tr><td>Earnings Per Share:</td><td id="c2r5"></td></tr>
      <tr><td>Gross Margin:</td><td id="c2r6"></td></tr>
      <tr><td>Net Debt To Total Capital:</td><td id="c2r7"></td></tr>
      <tr><td>Net Debt To Total Equity:</td><td id="c2r8"></td></tr>
      <tr><td>Net Margin:</td><td id="c2r9"></td></tr>
      <tr><td>Operating Margin:</td><td id="c2r10"></td></tr>
      <tr><td>Pre-Tax Margin:</td><td id="c2r11"></td></tr>
      <tr><td>Sales Per Share:</td><td id="c2r12"></td></tr>
      <tr><td>SGA To Sale:</td><td id="c2r13"></td></tr>
      <tr><td>Total Debt To Equity Ratio:</td><td id="c2r14"></td></tr>
      <tr><td>Total Debt To Total Assets Ratio:</td><td id="c2r15"></td></tr>
      <tr><td>Total Debt To Total Capital Ratio:</td><td id="c2r16"></td></tr>
      <tr><td>Total Ratio:</td><td id="c2r17"></td></tr>
    </tbody>
  </table>
</div>

<script type="module">
  // Import Finnhub API
  import finnhub from 'https://cdn.skypack.dev/finnhub';

  // Import ChatOpenAI
  import { ChatOpenAI } from "/node-modules/@langchain/openai/index.js";
  

  // Setup Finnhub API key
  const api_key = finnhub.ApiClient.instance.authentications['api_key'];
  api_key.apiKey = "cp3lm91r01qs3665m6p0cp3lm91r01qs3665m6pg";
  const finnhubClient = new finnhub.DefaultApi();

  // Setup ChatOpenAI model
  const model = new ChatOpenAI({
    openAIApiKey: "sk-proj-WmdfhIvo8UtVRboGO7JYT3BlbkFJtwPKulxv4zpC5aJOtnOQ",
    modelName: "gpt-3.5-turbo",
    temperature: 0.9,
  });

  // Add event listener to button
  const btn = document.getElementById("btn");
  btn.addEventListener('click', async function() {
    var stockTicker = document.getElementById("myName").value;
    var divClose = document.getElementById("myDiv");
    divClose.remove();

    // Fetch financial data from Finnhub API
    finnhubClient.companyBasicFinancials(stockTicker, "all", async (error, data, response) => {
      if (error) {
        console.error("Error fetching data:", error);
        return;
      }

      // Display financial data
      document.getElementById("c2r2").innerHTML = data.series.annual.cashRatio[0].v;
      document.getElementById("c2r3").innerHTML = data.series.annual.currentRatio[0].v;
      document.getElementById("c2r4").innerHTML = data.series.annual.ebitPerShare[0].v;
      document.getElementById("c2r5").innerHTML = data.series.annual.eps[0].v;
      document.getElementById("c2r6").innerHTML = data.series.annual.grossMargin[0].v;
      document.getElementById("c2r7").innerHTML = data.series.annual.netDebtToTotalCapital[0].v;
      document.getElementById("c2r8").innerHTML = data.series.annual.netDebtToTotalEquity[0].v;
      document.getElementById("c2r9").innerHTML = data.series.annual.netMargin[0].v;
      document.getElementById("c2r10").innerHTML = data.series.annual.operatingMargin[0].v;
      document.getElementById("c2r11").innerHTML = data.series.annual.pretaxMargin[0].v;
      document.getElementById("c2r12").innerHTML = data.series.annual.salesPerShare[0].v;
      document.getElementById("c2r13").innerHTML = data.series.annual.sgaToSale[0].v;
      document.getElementById("c2r14").innerHTML = data.series.annual.totalDebtToEquity[0].v;
      document.getElementById("c2r15").innerHTML = data.series.annual.totalDebtToTotalAsset[0].v;
      document.getElementById("c2r16").innerHTML = data.series.annual.totalDebtToTotalCapital[0].v;
      document.getElementById("c2r17").innerHTML = data.series.annual.totalRatio[0].v;

      // Call ChatOpenAI for additional insights
      const AIresponse = await model.invoke(stockTicker);
      console.log("AI:", AIresponse.content);
      // Display AI response
      document.getElementById("c2r18").innerHTML = response.content; // Adjust this based on where you want to display AI response
    });
  });
</script>

</body>
</html>

However, I seem to be encountering an error when running the program using VS code and the Live Server extension. The particular error message I am receiving is:

GET http://127.0.0.1:5500/node-modules/@langchain/openai net::ERR_ABORTED 404 (Not Found)

I think that the error has something to do with the import statement for the langchain module. I have tried using the ./ and / prefixes to direct the import the 'node-module' folder where the langchain module is located to no avail. When I try to import the module directly using a local file path (C:/users/...) I receive an error stating "Not allowed to load local resource: ...".

Any help with this issue would be greatly appreciated.

Thank you in advance,

  • R

I have tried adjusting the import 'from' path but am receiving different errors, which leads me to believe that the problem is due to the import statement not being able to load the module from the correct place.

I have also tried using a CDN import path but have not found a CDN that currently hosts the langchain library/module without returning a 404 error.

<p>I am trying to write code in JavaScript (Node.js) that will take stock market data and analyze it using an LLM (langchain in particular). My code is below:</p>
<pre><code><!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Financial Data Lookup</title>
<style>
.myDiv {
position: absolute;
transform: translate(-50%, -75%);
top: 250px;
left: 50%;
width: 500px;
border: 10px outset lime;
background-color: blue;
text-align: center;
}
table, th, td {
border: 1px solid;
width: 500px;
}
</style>
</head>
<body>

<div class="myDiv" id="myDiv">
<h1 class="white-text" style="color: white;">Input Stock Ticker</h1>
<input type="text" id="myName" placeholder="ex. AAPL">
<button id="btn">Compile</button>
</div>

<div class="StockDataTable" id="StockDataTable" style="z-index: 2; position: absolute; top: 400px;">
<table style="margin-left:300px;">
<thead>
<tr>
<th colspan="2">Basic Financials</th>
</tr>
</thead>
<tbody>
<tr><td>Cash Ratio:</td><td id="c2r2"></td></tr>
<tr><td>Current Ratio:</td><td id="c2r3"></td></tr>
<tr><td>EBIT Per Share:</td><td id="c2r4"></td></tr>
<tr><td>Earnings Per Share:</td><td id="c2r5"></td></tr>
<tr><td>Gross Margin:</td><td id="c2r6"></td></tr>
<tr><td>Net Debt To Total Capital:</td><td id="c2r7"></td></tr>
<tr><td>Net Debt To Total Equity:</td><td id="c2r8"></td></tr>
<tr><td>Net Margin:</td><td id="c2r9"></td></tr>
<tr><td>Operating Margin:</td><td id="c2r10"></td></tr>
<tr><td>Pre-Tax Margin:</td><td id="c2r11"></td></tr>
<tr><td>Sales Per Share:</td><td id="c2r12"></td></tr>
<tr><td>SGA To Sale:</td><td id="c2r13"></td></tr>
<tr><td>Total Debt To Equity Ratio:</td><td id="c2r14"></td></tr>
<tr><td>Total Debt To Total Assets Ratio:</td><td id="c2r15"></td></tr>
<tr><td>Total Debt To Total Capital Ratio:</td><td id="c2r16"></td></tr>
<tr><td>Total Ratio:</td><td id="c2r17"></td></tr>
</tbody>
</table>
</div>

<script type="module">
// Import Finnhub API
import finnhub from 'https://cdn.skypack.dev/finnhub';

// Import ChatOpenAI
import { ChatOpenAI } from "/node-modules/@langchain/openai/index.js";


// Setup Finnhub API key
const api_key = finnhub.ApiClient.instance.authentications['api_key'];
api_key.apiKey = "cp3lm91r01qs3665m6p0cp3lm91r01qs3665m6pg";
const finnhubClient = new finnhub.DefaultApi();

// Setup ChatOpenAI model
const model = new ChatOpenAI({
openAIApiKey: "sk-proj-WmdfhIvo8UtVRboGO7JYT3BlbkFJtwPKulxv4zpC5aJOtnOQ",
modelName: "gpt-3.5-turbo",
temperature: 0.9,
});

// Add event listener to button
const btn = document.getElementById("btn");
btn.addEventListener('click', async function() {
var stockTicker = document.getElementById("myName").value;
var divClose = document.getElementById("myDiv");
divClose.remove();

// Fetch financial data from Finnhub API
finnhubClient.companyBasicFinancials(stockTicker, "all", async (error, data, response) => {
if (error) {
console.error("Error fetching data:", error);
return;
}

// Display financial data
document.getElementById("c2r2").innerHTML = data.series.annual.cashRatio[0].v;
document.getElementById("c2r3").innerHTML = data.series.annual.currentRatio[0].v;
document.getElementById("c2r4").innerHTML = data.series.annual.ebitPerShare[0].v;
document.getElementById("c2r5").innerHTML = data.series.annual.eps[0].v;
document.getElementById("c2r6").innerHTML = data.series.annual.grossMargin[0].v;
document.getElementById("c2r7").innerHTML = data.series.annual.netDebtToTotalCapital[0].v;
document.getElementById("c2r8").innerHTML = data.series.annual.netDebtToTotalEquity[0].v;
document.getElementById("c2r9").innerHTML = data.series.annual.netMargin[0].v;
document.getElementById("c2r10").innerHTML = data.series.annual.operatingMargin[0].v;
document.getElementById("c2r11").innerHTML = data.series.annual.pretaxMargin[0].v;
document.getElementById("c2r12").innerHTML = data.series.annual.salesPerShare[0].v;
document.getElementById("c2r13").innerHTML = data.series.annual.sgaToSale[0].v;
document.getElementById("c2r14").innerHTML = data.series.annual.totalDebtToEquity[0].v;
document.getElementById("c2r15").innerHTML = data.series.annual.totalDebtToTotalAsset[0].v;
document.getElementById("c2r16").innerHTML = data.series.annual.totalDebtToTotalCapital[0].v;
document.getElementById("c2r17").innerHTML = data.series.annual.totalRatio[0].v;

// Call ChatOpenAI for additional insights
const AIresponse = await model.invoke(stockTicker);
console.log("AI:", AIresponse.content);
// Display AI response
document.getElementById("c2r18").innerHTML = response.content; // Adjust this based on where you want to display AI response
});
});
</script>

</body>
</html>
</code></pre>
<p>However, I seem to be encountering an error when running the program using VS code and the Live Server extension. The particular error message I am receiving is:</p>
<p>GET <a href="http://127.0.0.1:5500/node-modules/@langchain/openai" rel="nofollow noreferrer">http://127.0.0.1:5500/node-modules/@langchain/openai</a> net::ERR_ABORTED 404 (Not Found)</p>
<p>I think that the error has something to do with the import statement for the langchain module. I have tried using the ./ and / prefixes to direct the import the 'node-module' folder where the langchain module is located to no avail. When I try to import the module directly using a local file path (C:/users/...) I receive an error stating "Not allowed to load local resource: ...".</p>
<p>Any help with this issue would be greatly appreciated.</p>
<p>Thank you in advance,</p>
<ul>
<li>R</li>
</ul>
<p>I have tried adjusting the import 'from' path but am receiving different errors, which leads me to believe that the problem is due to the import statement not being able to load the module from the correct place.</p>
<p>I have also tried using a CDN import path but have not found a CDN that currently hosts the langchain library/module without returning a 404 error.</p>
 

Latest posts

Top