{"record":{"id":"05208f01eab728f4","repo":"hcengineering/platform","slug":"missing-env-variable-port","errorCode":null,"errorMessage":"Missing env variable: Port","messagePattern":"Missing env variable: Port","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"services/mail/pod-mail/src/config.ts","lineNumber":149,"sourceCode":"    const missingKeys = [isEmpty(host) && 'SMTP_HOST', port === undefined && 'SMTP_PORT'].filter(Boolean)\n    throw Error(`Missing env variables for SMTP configuration: ${missingKeys.join(', ')}`)\n  }\n\n  return {\n    Host: host as string,\n    Port: port,\n    Username: username,\n    Password: password,\n    TlsMode: tlsMode ?? TlsOptions.UPGRADE,\n    DebugLog: debugLog,\n    AllowSelfSigned: allowSelfSigned\n  }\n}\n\nconst config: Config = (() => {\n  const port = parseNumber(process.env[envMap.Port])\n  if (port === undefined) {\n    throw Error('Missing env variable: Port')\n  }\n  const isSmtpConfig = !isEmpty(process.env[envMap.SmtpHost])\n  const isSesConfig = !isEmpty(process.env[envMap.SesAccessKey])\n  if (isSmtpConfig && isSesConfig) {\n    throw Error('Both SMTP and SES configuration are specified, please specify only one')\n  }\n  if (!isSmtpConfig && !isSesConfig) {\n    throw Error('Please specify SES or SMTP configuration')\n  }\n  const params: Config = {\n    port,\n    source: process.env[envMap.Source],\n    replyTo: process.env[envMap.ReplyTo],\n    sesConfig: isSesConfig ? buildSesConfig() : undefined,\n    smtpConfig: isSmtpConfig ? buildSmtpConfig() : undefined\n  }\n\n  return params","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/services/mail/pod-mail/src/config.ts#L131-L167","documentation":"pod-mail's config IIFE requires the server Port env variable via parseNumber; if it is undefined (or not parseable as a number), it throws 'Missing env variable: Port' during module load, preventing the service from starting.","triggerScenarios":"Starting pod-mail without the Port env var set, or with a non-numeric value that parseNumber cannot parse into a defined number.","commonSituations":"Missing the PORT entry in .env or deployment manifest; wrong envMap key so the expected variable name differs from what is set; local run without docker env defaults.","solutions":["Set the Port env variable (the name comes from envMap.Port in config.ts — check it, commonly 'PORT') to a numeric value like 4001.","Confirm the variable is numeric — parseNumber rejects non-numeric strings.","Check the envMap in pod-mail/src/config.ts to confirm the exact expected variable name.","Ensure your .env / secret is actually loaded (working directory, env_file directives)."],"exampleFix":"// before\n# .env missing port\nMAIL_HOST=...\n// after\nPORT=4001\nMAIL_HOST=...","handlingStrategy":"validation","validationCode":"const port = Number(process.env.PORT);\nif (!process.env.PORT || Number.isNaN(port)) {\n  throw new Error(`Missing or non-numeric Port env var: ${process.env.PORT}`);\n}","typeGuard":null,"tryCatchPattern":"try {\n  await import('./config');\n} catch (err) {\n  if (err instanceof Error && err.message === 'Missing env variable: Port') {\n    console.error('Set the Port env variable (numeric) before starting pod-mail');\n    process.exit(1);\n  }\n  throw err;\n}","preventionTips":["Check envMap in pod-mail/src/config.ts for the exact variable name expected for Port.","Add a startup env check that fails fast with a clear message.","Keep PORT numeric and unquoted.","Ensure the .env file with PORT is actually loaded (env_file, --env-file flags)."],"tags":["env","configuration","port","startup"],"backgroundTag":"missing-env-var","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}