src/node/app.ts/listen
export const listen = async (server: http.Server, { host, port, socket, "socket-mode": mode }: ListenOptions) => {
  if (socket) {
    try {
      await fs.unlink(socket)
    } catch (error: any) {
      handleArgsSocketCatchError(error)
    }
  }
  await new Promise<void>(async (resolve, reject) => {
    server.on("error", reject)
    const onListen = () => {
      // Promise resolved earlier so this is an unrelated error.
      server.off("error", reject)
      server.on("error", (err) => util.logError(logger, "http server error", err))
      resolve()
    }
    if (socket) {
      server.listen(socket, onListen)
    } else {
      // [] is the correct format when using :: but Node errors with them.
      server.listen(port, host.replace(/^\[|\]$/g, ""), onListen)
    }
  })

  // NOTE@jsjoeio: we need to chmod after the server is finished
  // listening. Otherwise, the socket may not have been created yet.
  if (socket && mode) {
    await fs.chmod(socket, mode)
  }
}