tcpproxy.js error: getaddrinfo ENOTFOUND localhost and solutions

 

Error case

Case of error appears: Before my project executed locally npm run dev can be successfully run. In the case of a broken network, carried out npm run dev, the first time being given, then realized the net was broken. And so there is a net re-run npm run dev, error still occurs.
Error message:

Error: getaddrinfo ENOTFOUND localhost
    at errnoException (dns.js:50:10)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:95:26)

Specific Screenshot:
clipboard.png

Check the information, most people simply to modify the hosts configuration. But for me this weak chicken, I would like to know why the error, and how to modify the host file. . .

OK Closer to home, the article mentioned, according to error contents, concluded that the problem of localhost. There may be no binding 127.0.0.1 localhost, when I was not bound 127.0.0.1 localhost it, because I stock of knowledge in this area is zero, so I still do not quite understand the reason being given.

Solution

1. Open the hosts file

终端执行:**sudo vim /etc/hosts**,打开hosts文件。

2. Edit the hosts file

按 **i** 进入编辑模式,如果你的hosts文件最后一行有 **0.0.0.0 account.xxx.xxx**,在这一行的上一行输入 **127.0.0.1 localhost**;没有,则在最后一行输入**127.0.0.1 localhost**。

3. Save the hosts file

按 **esc** 退出编辑模式,最后输入**:wq**,保存并退出(:(英文冒号)表示进入了底线命令模式,在底线命令模式下,q表示退出程序,w表示保存文件,所以:wq表示保存并退出,这里涉及到vim的简单使用,找度娘了解更多~)。

episode

In my first open the hosts file, see the hosts file has 127.0.0.1 localhost, already bound to think that localhost 127.0.0.1, Nao Lege Oolong. In fact represent a # is a comment that line, be ashamed ~
clipboard.png

 

 

var net = require("net");

process.on("uncaughtException", function(error) {
  console.error(error);
});

if (process.argv.length != 5) {
  console.log("usage: %s <localport> <remotehost> <remoteport>", process.argv[1]);
  process.exit();
}

var localport = process.argv[2];
var remotehost = process.argv[3];
var remoteport = process.argv[4];

var server = net.createServer(function (localsocket) {
  var remotesocket = new net.Socket();

  remotesocket.connect(remoteport, remotehost);

  localsocket.on('connect', function (data) {
    console.log(">>> connection #%d from %s:%d",
      server.connections,
      localsocket.remoteAddress,
      localsocket.remotePort
    );
  });

  localsocket.on('data', function (data) {
    var flushed = remotesocket.write(data);
    if (!flushed) {
      localsocket.pause();
    }
  });

  remotesocket.on('data', function(data) {
    var flushed = localsocket.write(data);
    if (!flushed) {
      remotesocket.pause();
    }
  });

  localsocket.on('drain', function() {
    remotesocket.resume();
  });

  remotesocket.on('drain', function() {
    localsocket.resume();
  });

  localsocket.on('close', function(had_error) {
    console.log("%s:%d - closing remote",
      localsocket.remoteAddress,
      localsocket.remotePort
    );
    remotesocket.end();
  });

  remotesocket.on('close', function(had_error) {
    console.log("%s:%d - closing local",
      localsocket.remoteAddress,
      localsocket.remotePort
    );
    localsocket.end();
  });

});

server.listen(localport);

console.log("redirecting connections from 127.0.0.1:%d to %s:%d", localport, remotehost, remoteport);

  

 

Guess you like

Origin www.cnblogs.com/kissfu/p/12447223.html