Reputation: 21
I made an express Nodejs server and set the static folder. The CSS has access to the page, but the JS does not find any elements. Everything is NULL.
app.use(express.static(__dirname + '/static'))
app.get('/', (req, res) => {
res.render('index')
})
//test from clientside index.js
document.body.append('test')
<script src="js/index.js"></script>
<link rel="stylesheet" href="style/main.css">
What am I doing wrong?
Upvotes: 0
Views: 26
Reputation: 24691
DOM doesn't load yet when your JS runs. It's not related to EJS, that's just how every script works.
Add defer
attribute
<script defer src="js/index.js"></script>
Upvotes: 2