@maxbo/free-port
A utility to free a port prior to use. Add this before starting a server and it will kill the process using the port, optionally prompting before doing so. It will also stop docker containers without stopping the entire docker process.
tcp-port-used
A simple Node.js module to check if a TCP port is already bound.
port-get
Get an available TCP port (a minimal CJS module)