未捕获的SyntaxError:意外的令牌< ,在NodeJs中

时间:2018-01-09 05:52:05

标签: javascript node.js

我正在尝试在NodeJS中呈现html页面。当我刷新浏览器时,我收到此错误

Uncaught SyntaxError: Unexpected token <

如果我提供CDN路径,则表示没有显示错误。

<html>
<head>
<title>Welcome</title>
</head>
<body>
    <h1>Welcome</h1>
    <label>Username:</label>
    <input type="text" name="uname" id="uname"><br>
    <label>First name:</label>
    <input type="text" name="fname" id="fname"><br>
    <input type="submit" name="submit" id="btn">
    <script type="text/javascript" src="script.js"></script>
    <script type="text/javascript"  src="jq.js"></script>
</body>
</html>

NodeJs代码 - main.js

var http = require('http');
var fs = require('fs');

http.createServer(function(req,res){
res.writeHead(200,{'Content-type':'text/html'});
fs.readFile('index.html',function(err,data){
    if (err) {
        res.writeHead(404);
        res.write('File Not Found');
    } else {
        res.write(data);
    }
    res.end();
});
}).listen(8800);

0 个答案:

没有答案