这是我的代码:
index.js
"took 0 seconds"
index.html:
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
app.get('/js/client_world.js', function(req, res){
res.sendFile(__dirname + '/js/client_world.js');
});
io.on('connection', function(socket){
console.log("A user is connected");
socket.on('disconnect', function(){
console.log("User disconnected");
});
});
http.listen(3000, function(){
console.log("Listenng to port 3000")
});
第三个文件client_world,js,我要从数据库中读取数据。
第一行
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="/socket.io/socket.io.js"></script>
<script src="//threejs.org/build/three.min.js"></script>
<script src="/js/client_world.js"></script>
</head>
<body>
<div id="container"></div>
<script>
var socket = io();
socket.on('connect', function(){
loadWorld();
});
</script>
</body>
</html>
导致错误。 这种访问数据库的方式是否错误?预先感谢您的提示。