3 Replies Latest reply on Jul 29, 2014 11:03 AM by AllynH

    Galileo - Node.js won't create WebServer.

    AllynH

      Hi all,

      I have been trying to create a WebServer using Node.js - however the WebServer doesn't seem to be working for me.

       

      I am using the base Node.js version (0.8.18-r0 I think).

      I have tried the WebServer example from www.nodejs.org website:

      var http = require('http');
      http.createServer(function (req, res) {
        res.writeHead(200, {'Content-Type': 'text/plain'});
        res.end('Hello World\n');
      }).listen(1337, '127.0.0.1');
      console.log('Server running at http://127.0.0.1:1337/');
      

       

      I can then run the example like so:

      % node example.js
      Server running at http://127.0.0.1:1337/
      

       

      However when I navigate to localhost:1337 or http://127.0.0.1:1337/ the WebServer is not running.

       

      When I use the Arduino Ethernet WebServer example, the WebServer will run for me.

       

      Any input appreciated!

        • 1. Re: Galileo - Node.js won't create WebServer.
          Intel_Alvarado

          Hi AllynH,

          Have you checked that your Galileo board and the IP address of the Webserver are on the same network? I believe they need to be in order to work. We have already tried this but setting the Galileo as a hotspot. I hope you find this useful.

          Regards,
          Sergio

          • 2. Re: Galileo - Node.js won't create WebServer.
            AllynH

            Hi Sergio,

            Sorry - I'm not following you when you say:

            Have you checked that your Galileo board and the IP address of the Webserver are on the same network?

            Basically I have the Galileo connected to my router via Ethernet. I am creating the WebServer using the IP address 127.0.0.1 and port 1337.

            So I should be able to navigate to localhost:1337 to find the WebServer..?

             

            Thanks for the reply!

            • 3. Re: Re: Galileo - Node.js won't create WebServer.
              AllynH

              Hi Sergio,

               

              You were right, I must have changed the IP address on my board when I ran the WebServer sketch...

              So it looks like I can't use the 127.0.0.1 IP address to host my WebServer.

               

              My Galileo was using 192.168.1.55, so I needed to use:

              var http = require('http');  
              http.createServer(function (req, res) {  
                res.writeHead(200, {'Content-Type': 'text/plain'});  
                res.end('Hello World\n');  
              }).listen(1337, '192.168.1.55');  
              console.log('Server running at http://192.168.1.55:1337/'); 
              

               

              The Arduino Ethernet example Webserver also changed my IP address to: 192,168,1,177, which I hadn't realised...

               

              Thanks for the help - now to get practicing some JavaScript