에서 특정 node.js 메서드를 호출하는 방법 내 응용 프로그램에서는 node.js 파일에서 많은 메서드를 만들었습니다. 클라이언트 쪽 javascript에서 특정 메서드를 호출 할 수 있습니다.클라이언트 측 javacript
socket.emit("callMethod", {"methodName":"method3"});
를 그리고 서버에서 :
socket.on("callMethod", function(data) {
if(data["methodName"] == "method3") {
exports.method3();
}
});
당신은 돈 '아래
는
exports.method1=function(){
}
exports.method2=function(){
}
exports.method3=function(){
}
AJAX 나 NowJS 또는 DNode와 같은 RPC를 사용하면됩니다. – StuR