S
S
Stanislav Nekrasov2018-06-27 22:09:52
Computer networks
Stanislav Nekrasov, 2018-06-27 22:09:52

How to create node js server from home computer?

I have a problem. I just can’t make it so that from the Internet (using a white ip) you can go to my web page. I found the ip on the site 2ip.ru. Maybe you need to buy a white ip from the provider? I have already set up a firewall on the router and computer, set up NAT, set a gray permanent ip - 192.168.1.200. In Node JS I use http, ws. Maybe in http you need to set not localhost, but 0.0.0.0? Port by the way, 2000 and 2001 respectively for http and ws. I'm trying to access the site by ip: AAA.BBB.CCC.DDD:2000 .
Server test code to test functionality.

var HTTP = new require("http");
var FS = new require('fs');
const HTML = FS.readFileSync('server.html', 'utf8');
HTTP.createServer(function (req, res) {
  res.writeHead(200, {"Content-Type": "text/html"});
  res.end(HTML);
}).listen(2000, "localhost", function () {console.log("Server started!")});

Answer the question

In order to leave comments, you need to log in

5 answer(s)
#
#, 2018-06-27
@mindtester

192.168.1.200 is not grey, not brown, you are local
or buy an external legal address from the provider, or use services like dyndns or dlinkddns (from the router manufacturer) ... or ngrok.com (the author / owner warns - the service is not intended for loads)
ps as noted in the comments, services like dyndns or dlinkddns can be used, provided that your router receives at least a session, but a real "white" address. and 2ip.ru can show the provider's proxy address, through which many clients can go
ngrok.com will work in any situation
pps ... otherwise there are some providers that really do not sell white ip

A
alekssamos, 2018-06-28
@alekssamos

Previously, Rostelecom issued white (external) dynamic addresses, but now it has stopped, if you reload it 20 times, you might be lucky.
And yes, do not confuse the concepts of dynamic and "gray" address.
Dynamic - changes with each connection, may be different.
"gray" - not available from the Internet.

S
s0L, 2014-10-16
@Mist8

Because by default it treats right_answer as a local variable. In your function, add the line global right_answer at the very beginning

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question