Struggling to set up a basic Express server with accompanying HTML and JS files. Despite multiple attempts, I can't get the JS file to properly load.
index.js
:
const express = require("express");
const app = express();
const path = require("path");
app.set('view engine', 'ejs')
app.use(express.static(__dirname + '/public'));
app.listen(3000, () => {
console.log("Running on port 3000");
});
index.html
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Express App</title>
</head>
<body>
Homepage
<script src="login.js" type="text/javascript"></script>
</body>
</html>
login.js
:
function login () {
return (
<>
<p>hi</p>
</>
)
};
Unfortunately, every attempt leads to an error message such as Cannot GET, 404, or others.