【发布时间】:2015-10-05 11:47:43
【问题描述】:
我正在使用节点服务器制作聊天应用程序,但是当我启动节点服务器并将浏览器指向 localhost:3000 时,它会加载 HTML 文档,而不是加载 HTML 文档时应该加载的 CSS 文件。如何加载 CSS 文件以便 HTML 文档使用它?
HTML 文档代码
<html>
<head>
<title>Socket.IO Chat by Flow</title>
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script src="chat.js"></script>
</head>
<link rel="stylesheet" type="text/css" href="css.css">
<body>
<table align="center" id="chat-box">
<td>
<ul id="messages"></ul>
<form action="">
<input type="text" placeholder="Press enter to send a message..." autocomplete="off" id="m">
</form>
</td>
</table>
</body>
JavaScript 文档代码
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var port = 3000;
app.get('/', function(req, res){
res.sendFile(__dirname + '/chat.html');
});
io.on('connection', function(socket){
});
http.listen(port, function(){
console.log('Listening on port: ' + port);
});
【问题讨论】:
标签: javascript html css server