[英]Node.js sending data to vps server
我正在嘗試將數據從 client.js 發送到托管在 vps 上的服務器,然后將另一個數據返回給 client.js。
像這樣:client.js >data> server.js >data2> client.js
我的 client.js 文件:
var http = require('http');
var option = {
hostname : "51.x.x.x" ,
port : 8000 ,
//data?: "{}",
method : "POST",
path : "/"
}
var request = http.request(option , function(resp){
resp.on("data",function(chunck){
console.log(chunck.toString());
});
});
request.end();
/* server.js sending data to client.js but I don't know how to send data to server.js */
和 server.js 文件
var http = require('http');
http.createServer(function (req, res) {
if (req.method == 'POST') {
console.log('Res > post');
res.end('data from server.js (post)')
}
else {
console.log("Res > get");
res.end('data form server.js (get)');
}
}).listen(8000);
console.log('Running server with port 8000...');
那么,有沒有辦法將數據從 client.js 發送到 server.js?
您的 client.js 也是節點應用程序嗎? 如果是這樣,websockets 可能會幫助您建立雙向通信。 https://socket.io/get-started/chat/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.