Trying to get the simplest node server interacting with the browser, with this:
var http = require('http');
http.createServer(function(req, res){
res.writeHead( 200, { "content-Type" : 'text/plain' } )
res.send('Hello world');
}).listen(1337, '192.168.1.2');
but localhost won't do it..
localhost refused to connect
Thats the IPv4 address. Am I missing something here?
0.1 (loopback address). So your client is trying to connect to any of the non-loopback addresses of your machine, while your server is listening only on the loopback address . So, no connection can be established. The solution to this problem is that connect to the same end point your server is listening on.
Problems occurring in Node. js application deployments can have a range of symptoms, but can generally be categorized into the following: Uncaught exception or error event in JavaScript code. Excessive memory usage, which may result in an out-of-memory error.
Use 0.0.0.0 and it will work both '192.168.1.2' and localhost.
Had the same problem and solved it like this:
var http = require('http');
http.createServer(function(req, res){
res.writeHead( 200, { "content-Type" : 'text/plain' } )
res.end('Hello world');
}).listen(1337);
On node Terminal: node filename.js
Leave it open, don't CTRL + C.
Go to webpage: localhost:1337
It should work. The problem is not closing the terminal or exiting the execution of the node File.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With