numberjak
numberjak

Reputation: 1255

I can't connect to my node express server on any other device on my network

Here is my server.js code:

var express        =         require("express");
var app            =         express();

app.get('/', function (req, res) {
  res.send('Hello World!')
})

app.listen(3000, '0.0.0.0', function () 
console.log('Example app listening on port 3000!')
})

Really simple, I just want to see it working on my other devices before I continue.

It works fine obviously on my laptop I'm running it off, but nothing else. Any ideas?

Upvotes: 0

Views: 2630

Answers (2)

Trishant Pahwa
Trishant Pahwa

Reputation: 2962

Try this maybe:

var http = require("http");
var express = require("express");
var service = express();

service.use(service.router);

service.get('/', function (req, res) {
  res.send('Hello World!')
});

var server = http.createServer(service);

app.listen(3000, function () {
console.log('Example app listening on port 3000!')
});

Upvotes: 1

Fredrik Krig
Fredrik Krig

Reputation: 104

  • Try removing the '0.0.0.0'
  • You also have a missing bracket.

Try This:

    app.listen(3000, function () {
      console.log('Example app listening on port 3000!');
    });

Read more: https://nodejs.org/api/http.html#http_server_listen_path_callback

Upvotes: 1

Related Questions