From 64777f85cc519c9c4c2c84c23d2afed6a916f3c4 Mon Sep 17 00:00:00 2001 From: Haoliang Gao Date: Wed, 16 May 2018 21:21:29 +0800 Subject: [PATCH] fix: ignore EADDRNOTAVAIL error when listen localhost (#33) if localhost refer to the ip that is not unkonwn on the machine, you will see the error EADDRNOTAVAIL https://stackoverflow.com/questions/10809740/listen-eaddrnotavail-error-in-node-js --- .travis.yml | 8 ++++---- appveyor.yml | 10 +++++----- lib/detect-port.js | 4 +++- package.json | 2 +- 4 files changed, 13 insertions(+), 11 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4a437ac..9edb713 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,10 @@ sudo: false language: node_js node_js: - - 4 - - 6 - - 7 - - 8 + - '4' + - '6' + - '8' + - '10' install: - npm i npminstall && npminstall script: diff --git a/appveyor.yml b/appveyor.yml index eb97f9a..d3108c3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,9 +1,9 @@ environment: matrix: - - nodejs_version: 4 - - nodejs_version: 6 - - nodejs_version: 7 - - nodejs_version: 8 + - nodejs_version: '4' + - nodejs_version: '6' + - nodejs_version: '8' + - nodejs_version: '10' install: - ps: Install-Product node $env:nodejs_version @@ -12,6 +12,6 @@ install: test_script: - node --version - npm --version - - npm run ci + - npm run test build: off diff --git a/lib/detect-port.js b/lib/detect-port.js index d501cf5..8e72399 100644 --- a/lib/detect-port.js +++ b/lib/detect-port.js @@ -56,7 +56,9 @@ function tryListen(port, maxPort, callback) { // 3. check localhost listen(port, 'localhost', err => { - if (err) { + // if localhost refer to the ip that is not unkonwn on the machine, you will see the error EADDRNOTAVAIL + // https://stackoverflow.com/questions/10809740/listen-eaddrnotavail-error-in-node-js + if (err && err.code !== 'EADDRNOTAVAIL') { return handleError(err); } diff --git a/package.json b/package.json index ac0b58e..a4e38b9 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "node": ">= 4.2.1" }, "ci": { - "version": "4, 6, 7, 8" + "version": "4, 6, 8, 10" }, "homepage": "https://github.com/node-modules/detect-port", "license": "MIT"