I am building a website and using an express.js server to capture information submitted through a form. Before setting up the server I already had the site built, using static js and css files. After connecting to the server, I was able to get the server to render the html and css stylesheet. But it won't show the vanilla js I had already coded. I only want to use the server for the form and have the vanilla javascript still render like before connecting to the server.
I have the files set up as:
root
index.html
app.js
public
css
styles.css
javascript
index.js
app.js
const express = require("express");
const https = require("https");
const path = require('path')
const app = express();
app.use(express.static(path.join(__dirname, '/public')));
app.use(express.urlencoded({ extended: false }));
app.use(express.json());
app.get("/", function (req, res) {
res.sendFile(__dirname + "/index.html");
});
index.html
<link rel="stylesheet" href="css/styles.css" />
<script src="javascript/index.js"></script>
What am I doing wrong here? Is there something I need to code in my index.js file to get it to connect to the server? Thanks in advance.
index.jsis being loaded just fine, but isn't working properly due to a problem with it's coding. Are you seeing any errors in the browser console? If you want further help with index.js, then show that code. It's also possible that your<script>tag for that file is improperly located in your HTML file.