An example of Socket.io with Node.Js on the beagle bone or Raspberry
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.2 KiB

3 years ago
  1. # Readme
  2. This repository guides you to implement a server using Node.js. A first instance is created to understand how to set a server, then the server code is used to read the contents and printed out. Finally, a new server instance is prepared to prepare an `index.html` page and change dynamically its contents and LED status by reading the status option selected by the user.
  3. ## Static server
  4. A static server is developed on static-server.js file:
  5. ```node
  6. const express = require("express");
  7. const app = express();
  8. const http = require("http");
  9. const server = http.createServer(app);
  10. app.get('/', (req, res)=>{
  11. res.send('<h1> Hello World</h1>');
  12. });
  13. server.listen(4040, ()=>{
  14. console.log('listen on http://beaglebone-black.local:4040');
  15. });
  16. ```
  17. ## Server information on a html file
  18. ```node
  19. const express = require("express");
  20. const app = express();
  21. const http = require("http");
  22. const server = http.createServer(app);
  23. app.get('/', (req, res)=>{
  24. res.sendFile(__dirname + '/index-static.html');
  25. //res.send('<h1> Hello World</h1>');
  26. });
  27. server.listen(4040, ()=>{
  28. console.log('listen on http://beaglebone-black.local:4040');
  29. });
  30. ```
  31. the contents of the .html file is a common file.