Last active
February 11, 2016 11:46
-
-
Save hughrawlinson/5524836 to your computer and use it in GitHub Desktop.
A Node server for showing temperature from a sensor on a Raspberry Pi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
res.writeHead(200, {'Content-Type': 'text/plain'}); | |
res.write('<html><body><h1>Welcome to W1-TempServ</h1>\n'); | |
var temp = ''; | |
fs.readFile('/home/simon/temp', 'utf8', function (err, data) { | |
if (err) throw err; | |
console.log(data); | |
res.write("<p>"+data+"</p></body></html>"); | |
res.end(); | |
}); | |
// Data will not work here because it's outside of the it's scope. | |
// it was defined in the fs.readFile callback, can't be accessed outside of that | |
// res.write(data); | |
//also because of js asynchronicity you'll need to write everything in the callback |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment