Error encountered while trying to load resource: the server returned a 404 (Not Found) status code. Unable to connect to JavaScript file

I'm having some trouble deploying a simple JavaScript/CSS/HTML app on Heroku. I'm facing issues with properly linking the JS files. The app works fine without any errors before deployment.

Here is my index.html:

<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
    <script type="text/javascript" 
        src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
    <title>Document</title>
</head>
<body class="mt-0">
    <button type="button" class="btn btn-primary ml-5 mt-5 position-fixed" style="right: 50px">Background mode</button>
    <-- more html code -->
    <script type="text/javascript" src='./js/sky-widget.js'></script>
    <script type="text/javascript" src='./js/examples.js'></script>
</body>
</html>

server.js:

const express = require('express')
const app = express();

const path = require('path');

app.use(express.static(path.join(__dirname, '/pub')));

app.get('/', (req, res) => {
    res.send('<h1>This should be the root route!</h1>')
})

// Error codes
app.get('/problem', (req, res) => {
    res.status(500).send('There was a problem on the server')
});


const port = process.env.PORT || 5000
app.listen(port, () => {
    log(`Listening on port ${port}...`)
}) 

package.json:

{
  "name": "weather-sky",
  "version": "1.0.0",
  "description": "Weather widget library",
  "main": "server.js",
  "scripts": {
    "start": "node server.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
  },
  "license": "ISC",
  "dependencies": {
    "express": "^4.16.4"
  }
}

I'm encountering a "Failed to load resource: the server responded with a status of 404 (Not Found)" error for both sky-widget.js and examples.js. Any assistance would be greatly appreciated.

Answer №1

Can you provide additional details on the example.js / sky-widget.js? Additionally, have you considered updating your static files with the following code snippet:

  • app.use(express.static(path.join(__dirname, 'public')));

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Pandoc fails to display SVG images when converting HTML to DOCX

I am currently utilizing pandoc for the conversion of a standalone html file (without external dependencies), incorporating all necessary css and js within the html itself. Within this HTML document, there are several svg graphs that have been generated th ...

Error in Node.js child_process: unable to access the property '_writableState' as it is undefined

I'm currently working on integrating ffmpeg's functionality into a Node.js API by utilizing the child_process library. However, I encounter an error when trying to pass data to ffmpeg's stdin pipe, specifically getting a TypeError: Cannot re ...

Utilizing Leaflet to Ensure Polylines Align with Roads

I have a scenario where I am loading markers from a database and then connecting them with a polyline to calculate the overall distance. This approach saves me from having to calculate the distance between each pair of markers individually. However, I&apo ...

What steps can I take to prevent all of my Cucumber.js steps from running simultaneously?

I need assistance with writing a Cucumber.js test that can effectively test the search form on my website. Currently, I am facing an issue where the subsequent steps run before the results page fully loads after entering a search term using Selenium Webdri ...

Using JavaScript to disable and re-enable an ASP.NET Timer control

I currently have a webpage built with ASP.Net that includes an ASP:Timer control <asp:Timer ID="TimerRefresh" runat="server" Interval="5000" Enabled="true" OnTick="TimerRefresh_Tick"> </asp:Timer> It is connected to an asp:UpdatePanel on the ...

How can I implement a Dynamic Input field using Angular?

Suppose there is an input field where a user enters an ID. Once the user clicks the "add" button, I need to send a request to my server to fetch a "name". Afterwards, I want to disable the text input field, hide the "add" button, and show a number input fi ...

What is the most effective way to show an error message within the login form itself?

I'm currently dealing with a dilemma involving my login.php and login_process.php files. The login form is in the former, while the validation process occurs in the latter. I'm struggling to figure out how to display error messages on the login f ...

What could be causing the errorHandler middleware to be triggered twice in an express application?

const express = require('express') const app = express(); function middleWear1(req, res, next) { throw Error() } function errorHandler(err, req, res, next) { console.log("error handled"); res.end("error occured at ser ...

Encountering issues with installing the hummus npm module

I encountered errors while attempting to install the hummus npm module. Can anyone explain why this issue is occurring, especially since I have successfully installed it before? My operating system is Windows 7. > C:\Users\hmudunuri\Desk ...

What is the best way to display JSON data in a readable format?

I received a JSON file with the following structure: { "data":{ "uuid":"123", "name":"TestData", "alias":null, "created_at":"2021-03-17T11:57:29.000000Z&q ...

Utilize JavaScript to determine the clicked button and dynamically modify relevant HTML elements

I have a website with several buttons that are meant to open or close specific HTML details. Here are some examples of my buttons: <button onClick="showdetail()" class="stage-detail">1</button> <button onClick="showdetail()" class="stag ...

Using Partial function input in TypeScript

I am in need of a function that can accept partial input. The function includes a variable called style, which should only have values of outline or fill, like so: export type TrafficSignalStyle = 'outline' | 'fill' let style: TrafficSi ...

Prevent clicking on a specific column in a table using Jquery

Attempting to utilize Jquery for clicking on a table row in order to navigate to a new page. However, encountering an issue with the last column containing a button that redirects to a new page when clicked on the edge. Is there a way to disable the oncl ...

Develop a heap structure that ranks items according to the frequency of the competitor field

Testing a mockup variable: [ { competitor: 1 }, { competitor: 1 }, { competitor: 1 }, { competitor: 1 }, { competitor: 2 }, { competitor: 3 }, { competitor: 4 }, { competitor: 4 }, ...

Is there a way to update the options value using AngularJS?

One common issue that many people (myself included) are facing is with the ng-options directive in AngularJS when populating a <select> tag. Setting the value for an option seems to be unclear based on the documentation. For example, using ng-option ...

Utilizing JQuery's .append() method for dynamically modifying the layout of a table

I have encountered an issue with my HTML table where I want to dynamically change the layout of the table based on the browser size. Here is a snippet of my basic code: <tr> <td class="row">E1</td> <td class="row">E2</td> ...

Merging two sections of code? Transforming user inputted YouTube URL into an embedded URL and subsequently swapping out the iframe source with the modified URL

I am looking for a way to allow users to paste their YouTube URL into an input field, click submit, and have the video load above the input field. However, regular YouTube URLs do not work in iframes, so they must be converted using regex. I came across t ...

Guide on retrieving JSON information through an AJAX request within an AngularJS Bootstrap modal

I am eager to implement the following functionality: a button that triggers a dialog/modal from Angular Bootstrap which showcases a loading indicator as the application retrieves JSON data from the server. Once the data is fetched, it should be displayed w ...

Using a JavaScript class rather than an ID for toggling visibility

As a complete newbie to JavaScript, I've come across similar questions but I'm lost when it comes to coding - help needed! So here's the code I have so far, and I'm hoping someone can assist me. Currently, I have JavaScript set up to s ...

How do you incorporate a basic if statement within a td tag in PHP?

My PHP script contains an if statement that retrieves the last index of ',' in a string: if($idx = strripos($output,','))//Get the last index of ',' in your output string { $ErrorCode = substr($output,$idx + 1,(strlen($outpu ...