"Hello World" Node.js on Raspberry Pi |
var http = require("http");
var server = http.createServer(function(request, response) {
response.writeHead(200, {"Content-Type": "text/plain"});
response.write("Hello World of Node.js, on Raspberry Pi");
response.end();
});
server.listen(8081);
This code setup a http server to monitor port 8081, using node.
Run node in Terminal:
$ node hellonode.js
or
$ node hellonode
From another PC in the network, open a browser and vist <Pi IP address>:8081 to visit the node's http server.
Related: Install Node.js on Raspberry Pi
No comments:
Post a Comment