2014-07-15 5 views
0

socket.io 웹 사이트의 간단한 채팅 자습서를 사용하여 nodejs 및 socket.io가있는 서버를 설정했지만 함께 사용할 수 있기를 원했습니다. 나의 기존 웹 페이지. php가 있고 .php 파일입니다. .html을 .php로 변경했을 때, html 파일처럼 PHP 파일을로드 할 수 없었습니다. 나는 얻는다 : 오류 : ENOENT, stat '/index.php'어떤 아이디어?Nodejs 및 socket.io index.html 대신 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

ENOENT는 오류입니다. ENTry.

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

확장 파일을 변경하는 경우 폴더의 파일 이름과 코드 (js 파일)를 업데이트해야합니다.

하지만 Nodejs는 PHP 코드를 실행할 수 없습니다.

How to integrate nodeJS + Socket.IO and PHP?

+0

링크가 도움이되었습니다. – Blubberguy22