Node.js Error: listen EADDRNOTAVAIL


C:\Users\dell\Desktop\node>node nodedemo.js
Confiugre: host=192.168.1.115, port=8080
Server created: [object Object]
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRNOTAVAIL 192.168.1.115:8080
    at Object.exports._errnoException (util.js:870:11)
    at exports._exceptionWithHostPort (util.js:893:20)
    at Server._listen2 (net.js:1221:19)
    at listen (net.js:1270:10)
    at net.js:1379:9
    at nextTickCallbackWith3Args (node.js:453:9)
    at process._tickCallback (node.js:359:17)
    at Function.Module.runMain (module.js:443:11)
    at startup (node.js:139:18)
    at node.js:968:3


cmd 看下本地ipconfig,然后输入自己的ip,就可以了

#!/usr/bin/env node

var port = 8080;
var host = '192.168.1.18';
console.log('Confiugre: host=' + host + ', port=' + port);

var http = require('http');
var server = http.createServer(function(req, res) {
     res.writeHead(200, {'Content-Type' : 'text/plain'});
     res.end('Welcome to our site!!!');
});
console.log('Server created: ' + server);

server.listen(port, host);

然后在http://192.168.1.18:8080/放入浏览器里面访问

你可能感兴趣的:(NodeJs)