I am a new programmer and trying to create a basic express server with an html and js file. No matter what I try I can’t seem to get the js file to load. Please help!
https://github.com/mswomley/basic-express-server
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>
Home page
<script src="login.js" type="text/javascript"></script>
</body>
</html>
login.js
function login () {
return (
<>
<p>hi</p>
</>
)
};
No matter what I try I get some kind of error. Cannot GET, 404, or others.
New contributor
Maggie S is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.