Skip to content

Commit

Permalink
fix: return null for port if server is not yet listening
Browse files Browse the repository at this point in the history
  • Loading branch information
gurpreetatwal committed Jan 22, 2020
1 parent 24a3bbd commit 26e81d3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ function incito(arg) {
Object.defineProperty(instance, 'port', {
enumerable: true,
configurable: true,
get: () => instance.address().port,
get: () => {
// .address() will return `null` if the server has not yet emitted the 'listening' event
const address = instance.address();
return address ? address.port : null;
},
});

return instance;
Expand Down

0 comments on commit 26e81d3

Please sign in to comment.