diff --git a/packages/adapter-node/src/index.js b/packages/adapter-node/src/index.js index a7a5c96b5184..f2e199152f40 100644 --- a/packages/adapter-node/src/index.js +++ b/packages/adapter-node/src/index.js @@ -3,6 +3,7 @@ import process from 'node:process'; import { handler } from 'HANDLER'; import { env, timeout_env } from 'ENV'; import polka from 'polka'; +import { unlink } from 'node:fs/promises'; export const path = env('SOCKET_PATH', false); export const host = env('HOST', '0.0.0.0'); @@ -56,6 +57,14 @@ if (socket_activation) { console.log(`Listening on file descriptor ${SD_LISTEN_FDS_START}`); }); } else { + if (path) { + try { + await unlink(path); + } catch (err) { + //ignore missing file errors + if (err.code !== 'ENOENT') throw err; + } + } server.listen({ path, host, port }, () => { console.log(`Listening on ${path || `http://${host}:${port}`}`); });