Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject: NodeJS as a HTTP Service
PostPosted: Wed Mar 19, 2014 4:01 am 
Offline
Newbie

Joined: Wed Mar 19, 2014 3:32 am
Posts: 2
I want to use node.js on my Ubuntu linode.
I have a basic javascript file 'server.js':
Code:
var http = require("http");

var app = http.createServer(function(request, response) {
  response.writeHead(200, {
    "Content-Type": "text/plain"
  });
  response.end("HTTP response from Express.\n");
});

app.listen(3000, "localhost");
console.log("Server running at http://localhost:3000/");


I start the 'server.js' package and should be listening on port 3000. But when I point a browser at my linode's ip:3000 there is no response.

I have tried declaring 'server.js' to listen to port 80, and I've also tried redirecting port 80 to 3000:
Code:
iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 3000


This same 'server.js' code snip-it works in my local Windows development environment.


Top
   
PostPosted: Wed Mar 19, 2014 5:09 am 
Offline
Senior Member

Joined: Sat Nov 27, 2010 8:21 pm
Posts: 63
You have explicitly created a localhost only server. Change

Code:
app.listen(3000, "localhost");


to

Code:
app.listen(3000);


Top
   
PostPosted: Wed Mar 19, 2014 11:42 pm 
Offline
Newbie

Joined: Wed Mar 19, 2014 3:32 am
Posts: 2
Thanks, I didn't realize that was happening. Works much better without a hostname specified.
Would there be an advantage to setting a hostname?


Top
   
PostPosted: Sun Apr 06, 2014 12:12 pm 
Offline

Joined: Sun Apr 06, 2014 12:05 pm
Posts: 1
Hi. I'm having this same problem. That is, when I go to [my ip address]:3000 I get "Oops! Google Chrome could not connect to [mu ip address:3000"

Here's my node.js script:

var http = require("http");

var app = http.createServer(function(request, response) {
response.writeHead(200, {
"Content-Type": "text/plain"
});
response.end("HTTP response from Node.\n");
});

app.listen(3000);
console.log('Running...');


I was wondering if it had something to do with iptables, which I'm only just starting to learn about and don't fully understand.

I added this, thinking it would help, but it didn't: -A INPUT -p tcp --dport 3000 -j ACCEPT


In any case, if it helps, here's the text of /etc/iptables.firewall.rules:

*filter

# Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't$
-A INPUT -i lo -j ACCEPT
-A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT

# Accept all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT

# Allow all outbound traffic - you can modify this to only allow certain traf$
-A OUTPUT -j ACCEPT

# Allow HTTP and HTTPS connections from anywhere (the normal ports for websit$
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT
-A INPUT -p tcp --dport 3000 -j ACCEPT

# Allow ports for testing
-A INPUT -p tcp --dport 8080:8090 -j ACCEPT

# Allow ports for MOSH (mobile shell)
-A INPUT -p udp --dport 60000:61000 -j ACCEPT

# Allow SSH connections
# The -dport number should be the same port number you set in sshd_config
-A INPUT -p tcp -m state --state NEW --dport 9973 -j ACCEPT

# Allow ping
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT

# Log iptables denied calls
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-$

# Reject all other inbound - default deny unless explicitly allowed policy
-A INPUT -j REJECT
-A FORWARD -j REJECT

COMMIT

"


Top
   
PostPosted: Sun Apr 06, 2014 12:15 pm 
Offline
Senior Member

Joined: Mon Jul 05, 2010 5:13 pm
Posts: 392
What is the output of the following command:

iptables-save

- Les


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group