2

I'm using Express 4 installed on an amazon ec2-server. I was wondering why I can't access my server with the public-ip:8000/

Here is my code for the server:

var express = require('express');
var http = require('http');
var app = express();

http.createServer(app).listen(8000);

app.get('/', function (req, res) {
  res.send('Hello World!')
});
Arjun Patel
  • 236
  • 2
  • 16

1 Answers1

1

First, you aren't setting up the Express and HTTP server correctly; ExpressJS is itself a wrapper for the HTTP module. This would be a correct setup:

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

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

app.listen(8000);

Edit: the issue actually had to do with the firewall of the server (along with the app). This answer helped solve the issue.

Community
  • 1
  • 1
Brendan
  • 2,549
  • 1
  • 13
  • 31