1 Reply Latest reply on Mar 2, 2016 12:01 PM by DiegoV_Intel

    Serving Up and HTML 'File' with the Edison

    KeenanRebera

      Hi, all!

       

      I got the Intel Edison Sparkfun Inventors Kit from Sparkfun. I'm doing tutorial number 5 and the tutorial has the Edison serve up a web page via socket.io like so:

       

      var server = http.createServer(function(req, res) {
        res.writeHead(200);
        res.write(" <!DOCTYPE html>  \
         <html>  \
         <head>  \
         <title>LED Controller</title>  \
         <script src='/socket.io/socket.io.js'></script>  \
         </head>  \
         <body>  \
         <p><button onclick='toggle()'>TOGGLE</button></p>  \
         <script>  \
         var socket = io.connect('http://" + 
        req.socket.address().address + ":" + 
        port + "'); \
         function toggle() { \
        socket.emit('toggle'); \
        } \
         </script>  \
         </body>  \
         </html>");
        res.end();
      });
      

       

      This is silly to me. I'm literally printing out HTML inside of Javascript. Then I'm printing out Javascript inside of printed HTML inside of Javascript.

       

      I'm just wondering if I can code the html into a separate file and then serve up that file instead of doing it like this.

       

      Thanks! - Runningman.