-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.js
44 lines (33 loc) · 796 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use strict'
const os = require('os')
const platform = os.platform()
const parser = require('./lib/parser')
module.exports = function (port) {
let results = {}
switch (platform) {
case 'win32':
results = parser.windows(port)
break
case 'linux':
results = parser.linux(port)
break
case 'darwin':
results = parser.lsof(port)
break
default:
console.warn(platform + ' operating system not supported.')
return null
}
let pids = Object.keys(results)
switch (pids.length) {
case 0:
return null
case 1:
let data = results[pids[0]]
data.pid = pids[0]
return data
default:
console.warn('Recognized more than one process running on port ' + port + '!')
return results
}
}