From b9f43d976cb1cf9e363cb81cf17fb8b3e66b564d Mon Sep 17 00:00:00 2001 From: xdd <45672942@qq.com> Date: Sat, 19 Oct 2024 20:36:19 +0800 Subject: [PATCH] fix: enhance error handling in findAndKillProcess --- README.md | 2 +- index.js | 2 +- package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index c4ac84c..974fe12 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# kill-port-process-cli +# kill-port-process-cli ![npm downloads](https://img.shields.io/npm/dt/kill-port-process-cli) A CLI tool to kill processes by port. This tool allows you to terminate processes running on specified ports. It is useful for developers who need to quickly free up ports during development. diff --git a/index.js b/index.js index f5a5905..812a58c 100644 --- a/index.js +++ b/index.js @@ -36,7 +36,7 @@ const findAndKillProcess = (port) => { } const pid = process.platform === 'win32' - ? stdout.split('\n').find(line => line.includes('LISTEN')).trim().split(/\s+/).pop() + ? stdout.split('\n').find(line => line.includes('LISTEN'))?.trim().split(/\s+/).pop() : stdout.split('\n').map(line => line.trim()).filter(line => line).pop(); if (pid) { diff --git a/package.json b/package.json index afc396b..591d73d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kill-port-process-cli", - "version": "1.0.8", + "version": "1.0.9", "description": "A CLI tool to kill processes by port", "main": "index.js", "bin": {