When I load the page, the
What is up
shows up, but the "Hello World" from the script.js doesn't. Any help?The directory looks like this
project
|
+-- node modules
|
+-- javascript
| |
| +-- script.js
|
+-- views
| |
| | +-- index.ejs
|
+-- server.js
|
+-- package.json
index.ejs file
<html lang="en">
<head>
<meta charset="utf-8">
<title>Index</title>
<meta name="description" content="Index">
</head>
<body>
<h1>What is up?</h1>
<div id = "container">
</div>
</body>
<script src = "javascript/script.js">
// var container = document.getElementById("container");
// var content = document.createTextNode("Hello, World!");
// container.appendChild(content);
</script>
</html>
The commented out code in the script is exactly whats included in the script.js file. If I uncomment it, and have the code running in the ejs file, it works. Just not if in the external script.js
server.js file
const express = require('express')
const app = express()
app.set('view-engine', 'ejs')
app.use(express.static('project/javascript'))
app.get('/', (req, res) => {
res.render('index.ejs')
})
app.listen(3000)