Answer the question
In order to leave comments, you need to log in
How to fix broken import in client js file in html working in node.js w/o express server?
Hello! Such a thing, there is a default server on node js w/o express:
const express = require('express')
const app = express()
app.get('/', function(req, res) {
res.sendFile(__dirname + 'index.html')
})
app.listen(8080, () => console.log('Server started!'))
<script src="./script.js"></script>
Answer the question
In order to leave comments, you need to log in
function require(url,cb){
let script = document.createElement('script');
script.setAttribute('type','application/javascript');
script.setAttribute('src',url);
if('function' == typeof cb)
script.addEventListener('load', cb, false);
document.head.appendChild(script);
return script;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question