我用Node.js运行一个简单的http服务器:
var http = require('http');
var fs = require('fs');
var index = fs.readFileSync('index.html');
var sensor = require('ds18x20');
var temp = sensor.get('sensorID');
http.createServer(function(req,res) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.end(index);
}).listen(80);
console.log(temp);
Run Code Online (Sandbox Code Playgroud)
我的index.html文件:
<html>
<head>
</head>
<body>
My temperature:
//space for variable: temp
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
现在,我想在index.html文件中打印服务器端变量:temp.但我不知道该怎么做.
也许有人可以帮助我从服务器到客户端交换变量.