Nodejs和socket.io使用index.php而不是index.html

时间:2014-07-15 17:58:55

标签: php html node.js sockets socket.io

使用socket.io网站上的简单聊天教程,我设置了一个带有nodejs和socket.io的服务器,但是我希望能够将它与我之前存在的网页一起使用,该网页中包含了php,并且就此而言。 php文件。当我将.html更改为.php时,我无法像html文件那样加载php文件。我得到:错误:ENOENT,stat'/index.php'任何想法?

var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);

app.get('/', function(req, res){
  res.sendfile('index.php');
});

io.on('connection', function(socket){
  socket.on('chat message', function(msg){
    io.emit('chat message', msg);
  });
});

http.listen(3000, function(){
  console.log('listening on *:3000');
});

编辑:忘记在上面的代码中将“index.html”更改为“index.php”,现在它是正确的。

1 个答案:

答案 0 :(得分:1)

ENOENT是错误NO ENTry。

res.sendfile(__dirname + '/index.html');

如果更改扩展文件,则必须更新文件夹和代码(js文件)中的文件名。

但是Nodejs无法执行你的php代码。

How to integrate nodeJS + Socket.IO and PHP?

相关问题