{"name":"find-process","version":"2.1.0","keywords":["node","process","pid","port"],"author":{"name":"zoujie","email":"yibn2008@gmail.com"},"license":"MIT","_id":"find-process@2.1.0","maintainers":[{"name":"yibn2008","email":"yibn2008@gmail.com"}],"homepage":"https://github.com/yibn2008/find-process#readme","bugs":{"url":"https://github.com/yibn2008/find-process/issues"},"bin":{"find-process":"dist/cjs/bin/find-process.js"},"dist":{"shasum":"b0d239115299f56ed3e43fec4d584efad0e9e79a","tarball":"http://registry-npm.ywwl.com/find-process/download/find-process-2.1.0.tgz","fileCount":69,"integrity":"sha512-uf1F6mFDAltKaVHf4/zlXstW/k01qPwv+OB6bMRnuIycO6dTmQo+sUW1Uj/xJzGmmVarYW4ZM7TBBbBy6f/y0g==","signatures":[{"sig":"MEQCIEdOewMzpMvMWa6CTTB7lYSMHCihICnr1fzi1MD9+ADPAiBzShtl0kTOWJOZ9Rf62MKwgH625n0JOdo65c5hsbnkOQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":140265,"size":21866,"noattachment":false,"key":"/find-process/-/find-process-2.1.0.tgz"},"main":"dist/cjs/index.js","types":"dist/cjs/index.d.ts","ensure":{"deps":{"checkDirs":["lib/*","bin/*","*.js"]}},"module":"dist/esm/index.js","exports":{"import":"./dist/esm/index.js","require":"./dist/cjs/index.js"},"gitHead":"4795dd42443789bef5b1b5ff89eeccdd4a45f9d3","scripts":{"dev":"tsc --watch","lint":"standard --fix && npm-ensure -t deps","test":"npm run build && mocha -r ts-node/register test/*.test.ts && standard","build":"rimraf dist && tsc -p tsconfig.json && tsc -p tsconfig.esm.json && node scripts/postbuild.js","prepare":"npm run build","type-check":"tsc --noEmit","check-version":"node scripts/check-version.js","prepublishOnly":"npm run build && npm run check-version","update-history":"node scripts/update-history.js"},"_npmUser":{"name":"yibn2008","email":"yibn2008@gmail.com"},"standard":{"ignore":["/node_modules","/doc","/example","/test","/dist","index.d.ts"],"globals":["describe","beforeEach","afterEach","it"]},"repository":{"url":"git+https://github.com/yibn2008/find-process.git","type":"git"},"_npmVersion":"11.6.3","description":"find process info by port/pid/name etc.","directories":{},"_nodeVersion":"20.19.3","dependencies":{"chalk":"~4.1.2","loglevel":"^1.9.2","commander":"^12.1.0"},"publishConfig":{"registry":"https://registry.npmjs.org"},"_hasShrinkwrap":false,"packageManager":"pnpm@9.15.1+sha512.1acb565e6193efbebda772702950469150cf12bcc764262e7587e71d19dc98a423dff9536e57ea44c49bdf790ff694e83c27be5faa23d67e0c033b583be4bfcf","devDependencies":{"glob":"^13.0.0","mocha":"^11.7.1","eslint":"^9.30.1","rimraf":"^6.0.1","ts-node":"^10.9.2","standard":"^17.1.2","npm-ensure":"^1.3.0","typescript":"^5.8.3","@types/node":"^24.0.10","@types/mocha":"^10.0.10"},"_npmOperationalInternal":{"tmp":"tmp/find-process_2.1.0_1772285157437_0.43371568762768087","host":"s3://npm-registry-packages-npm-production"},"readme":"# find-process\n\n[![Node.js CI](https://github.com/yibn2008/find-process/actions/workflows/nodejs.yml/badge.svg)](https://github.com/yibn2008/find-process/actions/workflows/nodejs.yml)\n[![npm version](https://img.shields.io/npm/v/find-process.svg)](https://www.npmjs.com/package/find-process)\n[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg)](http://standardjs.com/)\n[![TypeScript](https://img.shields.io/badge/TypeScript-5.8-blue.svg)](https://www.typescriptlang.org/)\n\nWith find-process, you can:\n\n- find the process which is listening specified port\n- find the process by pid\n- find the process by given name or name pattern\n\nWe have covered the difference of main OS platform, including **macOS**, **Linux**, **Windows**\nand **Android** (with [Termux](https://termux.com)).\n\n## Features\n\n- ✅ **Full TypeScript Support** - Written in TypeScript with complete type definitions\n- ✅ **Cross-platform** - Works on macOS, Linux, Windows, and Android\n- ✅ **CLI Tool** - Command-line interface for quick process lookup\n- ✅ **Node.js API** - Programmatic access with Promise-based API\n- ✅ **Modern Build** - ES2020 target with source maps and declaration files\n\n## CLI\n\nInstall find-process as a CLI tool:\n\n```sh\n$ npm install find-process -g\n```\n\nUsage:\n\n```sh\n\n  Usage: find-process [options] <keyword>\n\n\n  Options:\n\n    -V, --version      output the version number\n    -t, --type <type>  find process by keyword type (pid|port|name)\n    -p, --port         find process by port\n    -v, --verbose      print execute command\n    -d, --debug        print debug info for issue reporting\n    -h, --help         output usage information\n\n  Examples:\n\n    $ find-process node          # find by name \"node\"\n    $ find-process 111           # find by pid \"111\"\n    $ find-process -p 80         # find by port \"80\"\n    $ find-process -t port 80    # find by port \"80\"\n\n```\n\nExample:\n\n![image](https://user-images.githubusercontent.com/4136679/62670202-f49a6b00-b9c4-11e9-8692-7003c6c31a8a.png)\n\n## Node API\n\nYou can use npm to install:\n\n```sh\n$ npm install find-process --save\n```\n\n### TypeScript Usage\n\n```typescript\nimport find, { ProcessInfo, FindConfig } from \"find-process\";\n\n// Find process by PID\nfind('pid', 12345)\n  .then((list: ProcessInfo[]) => {\n    console.log(list);\n  })\n  .catch((err: Error) => {\n    console.log(err.stack || err);\n  });\n\n// With configuration options\nconst config: FindConfig = {\n  strict: true,\n  logLevel: 'warn'\n};\n\nfind('name', 'nginx', config)\n  .then((list: ProcessInfo[]) => {\n    console.log(`Found ${list.length} nginx processes`);\n  });\n```\n\n### JavaScript Usage\n\n```js\nconst find = require('find-process');\n\nfind('pid', 12345)\n  .then(function (list) {\n    console.log(list);\n  }, function (err) {\n    console.log(err.stack || err);\n  })\n```\n\n## API Reference\n\n### Function Signature\n\n```typescript\nfunction find(type: 'port' | 'pid' | 'name', value: string | number, options?: FindConfig | boolean): Promise<ProcessInfo[]>\n```\n\n### Arguments\n\n- `type` - The type of search, supports: `'port' | 'pid' | 'name'`\n- `value` - The value to search for. Can be RegExp if type is `'name'`\n- `options` - Optional configuration object or boolean for strict mode\n  - `options.strict` - Optional strict mode for exact matching of name (on Windows, `.exe` can be omitted)\n  - `options.logLevel` - Set logging level to `'trace' | 'debug' | 'info' | 'warn' | 'error'`. Useful for silencing netstat warnings on Linux\n  - `options.skipSelf` - Skip the current process when searching by name\n  - `options.verbose` - Print the internal shell command to stdout before executing\n  - `options.debug` - Write each command, its stdout, and its stderr to stderr (implies verbose)\n\n### Return Value\n\nReturns a Promise that resolves to an array of process information (`[]` means no processes found):\n\n```typescript\ninterface ProcessInfo {\n  pid: number;           // Process ID\n  ppid: number;          // Parent process ID\n  uid?: number;          // User ID (Unix systems)\n  gid?: number;          // Group ID (Unix systems)\n  name: string;          // Command/process name\n  bin?: string;          // Executable path (Unix systems)\n  cmd: string;           // Full command with arguments\n}\n```\n\n### Type Definitions\n\nThe package includes complete TypeScript definitions:\n\n```typescript\nimport { ProcessInfo, FindConfig, FindMethod } from 'find-process';\n```\n\n## Examples\n\n### Find process listening on port 80\n\n```typescript\nimport find from 'find-process';\n\nfind('port', 80)\n  .then((list) => {\n    if (!list.length) {\n      console.log('Port 80 is free now');\n    } else {\n      console.log(`${list[0].name} is listening on port 80`);\n    }\n  });\n```\n\n### Find process by PID\n\n```typescript\nimport find from 'find-process';\n\nfind('pid', 12345)\n  .then((list) => {\n    console.log(list);\n  })\n  .catch((err) => {\n    console.log(err.stack || err);\n  });\n```\n\n### Find all nginx processes\n\n```typescript\nimport find from 'find-process';\n\nfind('name', 'nginx', true)\n  .then((list) => {\n    console.log(`There are ${list.length} nginx process(es)`);\n  });\n```\n\n### Find processes with configuration options\n\n```typescript\nimport find from 'find-process';\n\nfind('name', 'nginx', { strict: true, logLevel: 'error' })\n  .then((list) => {\n    console.log(`Found ${list.length} nginx process(es)`);\n  });\n```\n\n### Using async/await\n\n```typescript\nimport find from 'find-process';\n\nasync function findNodeProcesses() {\n  try {\n    const processes = await find('name', 'node');\n    console.log(`Found ${processes.length} Node.js processes`);\n    \n    processes.forEach(proc => {\n      console.log(`PID: ${proc.pid}, Name: ${proc.name}, CMD: ${proc.cmd}`);\n    });\n  } catch (error) {\n    console.error('Error finding processes:', error);\n  }\n}\n```\n## Development\n\n### Prerequisites\n\n- Node.js 16+ \n- pnpm (recommended) or npm\n\n### Setup\n\n```bash\n# Clone the repository\ngit clone https://github.com/yibn2008/find-process.git\ncd find-process\n\n# Install dependencies\npnpm install\n\n# Build the project\npnpm run build\n\n# Run tests\npnpm test\n\n# Run linting\npnpm run lint\n```\n\n### Available Scripts\n\n- `pnpm run build` - Compile TypeScript to JavaScript\n- `pnpm run dev` - Watch mode for development\n- `pnpm test` - Run tests\n- `pnpm run lint` - Run linting and fix issues\n- `pnpm run type-check` - TypeScript type checking\n- `pnpm run check-version` - Verify version consistency\n- `pnpm run update-history` - Update HISTORY.md with recent commits\n\n## Reporting Issues\n\nIf `find-process` returns unexpected results (e.g. a process is not found, or the wrong PID is returned), please attach the output of the `--debug` flag when opening a GitHub issue. This dumps the exact shell commands that were run and their raw output, which is almost always enough to diagnose the problem.\n\n### How to collect debug output\n\nRun the same command that failed, but add the `-d` / `--debug` flag:\n\n```sh\n# Example: process not found on port 3000\nfind-process --debug -p 3000\n\n# Example: process name search returns nothing\nfind-process --debug node\n```\n\nThe output will look like this (debug lines go to stderr, results to stdout):\n\n```\n[debug] Platform : darwin\n[debug] Node     : v20.15.0\n[debug] Version  : 2.0.0\n\n[debug] Command: netstat -anv -p TCP && netstat -anv -p UDP\n[debug] stdout:\nActive Internet connections (including servers)\n...\n\n[debug] stderr:\n(empty)\n\n[debug] Command: ps -p 1234 -ww -o pid,ppid,uid,gid,args\n[debug] stdout:\nPID  PPID ...\n\n[debug] stderr:\n(empty)\n\n[debug] Please copy the above output and attach it to your issue:\n[debug] https://github.com/yibn2008/find-process/issues\n\n============================================================\nNo process found\n```\n\nTo capture the debug output, redirect stderr:\n\n```sh\nfind-process --debug -p 3000 2>debug.txt\n```\n\nPaste the contents into the **\"Debug output\"** section of the [bug report template](https://github.com/yibn2008/find-process/issues/new?template=bug_report.md).\n\n> **Note:** the debug output may contain process names and listening ports from your machine.\n> Review it before sharing if you are working in a sensitive environment.\n\n## Contributing\n\nWe welcome Pull Requests for bug fixes and new features. Please check the following before submitting a PR:\n\n- **Coding Style** - Follow the [Standard Style](https://github.com/feross/standard)\n- **TypeScript** - Ensure proper typing and no type errors\n- **Documentation** - Add documentation for every API change\n- **Unit Tests** - Add unit tests for bug fixes or new features\n- **Build** - Ensure `pnpm run build` completes successfully\n\n## License\n\n[MIT](LICENSE)\n\n","publish_time":1772285157589,"_cnpm_publish_time":1772285157589,"dist-tags":{"latest":"2.1.1"}}