【发布时间】:2021-07-31 20:40:29
【问题描述】:
所以我对节点完全绿色。我有带有 index.html 和 script.js 文件的基础网络。它工作正常,但现在我添加了 node.js 和正在运行它的文件 app.js。之后我的 script.js 没有正确加载到 html。除了styles.css 之外的所有文件都在同一个目录中,但是样式被正确加载到html。
抛出的错误: GET http://localhost:3000/script.js net::ERR_ABORTED 404(未找到)
index.html
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="styles/styles.css">
<script type="text/javascript" src="script.js"></script>
<title>Document</title>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.3/css/all.css" integrity="sha384-UHRtZLI+pbxtHCWp1t77Bi1L4ZtiqrqD80Kn4Z8NTSRyMA2Fd33n5dQ8lWUE00s/" crossorigin="anonymous">
</head>
script.js
window.addEventListener('load', function(){
document.getElementById('sampleeditor').setAttribute('contenteditable', 'true');
});
function format(command, value) {
document.execCommand(command, false, value);
}
app.js
const express = require('express')
const port = 3000;
const path = require('path')
const app = express()
app.get('/', function(request, response){
response.sendFile(path.join(__dirname + '/index.html'));
})
app.listen(port)
【问题讨论】:
标签: javascript html node.js