Currently facing an issue while trying to develop my first node application. The problem lies with the JavaScript file, as my CSS file is working fine which is causing confusion for me. Here is a snippet of my app.js code:
var express = require("express");
var app = express();
app.set("view engine", "ejs");
app.use(express.static(__dirname + '/public'));
Initially, I couldn't load my JavaScript file until I added line 4. However, after adding line 4, the changes made to my JavaScript file are not reflecting in the Chrome resources tab. Interestingly, my CSS file is functioning properly which adds to my dilemma.
When linking to the JavaScript file, I am using:
<script src="javascripts/main.js"></script>
Despite trying to troubleshoot by restarting the server and installing nodemon, the issue persists. The file structure of my project is as follows:
app.js
public
stylesheets
main.css
javascripts
main.js
Researching the problem online, I noticed other developers facing issues with connecting to static files. However, my problem is unique in the sense that once connected, any changes made to the JavaScript file are not being reflected in the browser.