SOC 직업 분류 기준
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
직접 명령은 검토 Prompt를 거치지 않습니다. 실행하기 전에 소스를 확인하세요.
npx skills add https://github.com/tomevault-io/skills-registry --skill nodejs-port-cleanup명령은 한 줄로 유지됩니다. 복사하기 전에 가로로 스크롤해 전체 내용을 확인하세요.
로컬 사본을 원하시나요? SkillsMP에서 현재 제공할 수 있는 파일을 다운로드하세요.
SKILL.md 표시 중
| Use when this capability is needed.
> Use when this capability is needed.
Review architecture and API design for the vfs-s3 project. Use when the user mentions @architect, asks to review an issue's design, discuss module boundaries, API shape, or architectural decisions for vfs-s3. Also trigger when the user wants to create an ADR (Architecture Decision Record) or evaluate a technical approach for the project. Intended for dispatch from Codex automation or Claude routines; GitHub trigger phrase: @vfs-s3-bot please prepare design doc Use when this capability is needed.
| name | nodejs-port-cleanup |
| description | | Use when this capability is needed. |
When restarting a development server, you often encounter EADDRINUSE: address already in use
errors because a previous instance is still running. This is especially common when:
Error: listen EADDRINUSE: address already in use :::PORTAdd this function to your Node.js server startup script:
import { execSync } from 'child_process';
/**
* Kills any existing process using the specified port.
* This prevents EADDRINUSE errors when restarting the server.
* Works on Windows by using netstat to find the PID and taskkill to terminate it.
* Works on Unix/Mac by using lsof to find and kill the process.
*/
function killProcessOnPort(port: number): void {
const isWindows = process.platform === 'win32';
try {
if (isWindows) {
// Use netstat to find the PID of the process listening on this port
// netstat output format: " TCP 0.0.0.0:3847 0.0.0.0:0 LISTENING 12345"
const netstatOutput = execSync(`netstat -ano | findstr :${port}`, {
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'], // Suppress stderr
});
// Parse each line to extract PIDs of listening processes
const lines = netstatOutput.trim().split('\n');
const pids = new Set<string>();
for (const line of lines) {
// Only target LISTENING connections on our exact port
if (line.includes('LISTENING')) {
// Split by whitespace and get the last column (PID)
const parts = line.trim().split(/\s+/);
const pid = parts[parts.length - 1];
if (pid && /^\d+$/.test(pid)) {
pids.add(pid);
}
}
}
// Kill each process found
for (const pid of pids) {
try {
execSync(`taskkill /PID ${pid} /F`, {
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
});
console.log(`Killed existing process on port ${port} (PID: ${pid})`);
} catch {
// Process may have already exited, ignore
}
}
} else {
// Unix/Mac: use lsof to find and kill the process
const lsofOutput = execSync(`lsof -ti:${port}`, {
encoding: 'utf-8',
stdio: ['pipe', 'pipe', 'pipe'],
});
const pids = lsofOutput.trim().split('\n').filter(Boolean);
for (const pid of pids) {
try {
execSync(`kill -9 ${pid}`, { stdio: ['pipe', 'pipe', 'pipe'] });
console.log(`Killed existing process on port ${port} (PID: ${pid})`);
} catch {
// Process may have already exited, ignore
}
}
}
} catch {
// No process found on port - this is fine, nothing to kill
}
}
// Call before creating the server
const PORT = 3000;
killProcessOnPort(PORT);
// Then create and start your server as normal
const server = http.createServer(/* ... */);
server.listen(PORT, () => {
console.log(`Server running at http://localhost:${PORT}`);
});
When the function successfully kills a process, you'll see:
Killed existing process on port 3847 (PID: 12345)
If no process was found (port was free), the function silently proceeds.
Before this fix:
> npx tsx scripts/my-server.ts
Error: listen EADDRINUSE: address already in use :::3847
After adding killProcessOnPort():
> npx tsx scripts/my-server.ts
Killed existing process on port 3847 (PID: 39592)
Server running at http://localhost:3847
netstat -ano to find PIDs and taskkill /F to force-killlsof -ti:PORT to find PIDs and kill -9 to force-kill/F on Windows, -9 on Unix) ensures stubborn processes are terminatedIf you need to manually kill a process on a port:
Windows:
# Find the PID
netstat -ano | findstr :3847
# Kill it
taskkill /PID <pid> /F
# Or via PowerShell
Stop-Process -Id <pid> -Force
Unix/Mac:
# Find and kill in one command
lsof -ti:3847 | xargs kill -9
child_process.execSync: https://nodejs.org/api/child_process.html#child_processexecsynccommand-optionsConverted and distributed by TomeVault — claim your Tome and manage your conversions.