{"id":"03e58cd4b5b895ac","repo":"expressjs/express","slug":"name-argument-is-required-to-req-get","errorCode":null,"errorMessage":"name argument is required to req.get","messagePattern":"name argument is required to req\\.get","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"lib/request.js","lineNumber":66,"sourceCode":" *     // => \"text/plain\"\n *\n *     req.get('content-type');\n *     // => \"text/plain\"\n *\n *     req.get('Something');\n *     // => undefined\n *\n * Aliased as `req.header()`.\n *\n * @param {String} name\n * @return {String}\n * @public\n */\n\nreq.get =\nreq.header = function header(name) {\n  if (!name) {\n    throw new TypeError('name argument is required to req.get');\n  }\n\n  if (typeof name !== 'string') {\n    throw new TypeError('name must be a string to req.get');\n  }\n\n  var lc = name.toLowerCase();\n\n  switch (lc) {\n    case 'referer':\n    case 'referrer':\n      return this.headers.referrer\n        || this.headers.referer;\n    default:\n      return this.headers[lc];\n  }\n};\n","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/expressjs/express/blob/a3714473feb3d2908add734d340e7755fd85e0a3/lib/request.js#L48-L84","documentation":"Express's req.get() (aliased req.header()) reads a request header by name. At lib/request.js:65-67 it throws a TypeError when the name argument is falsy (undefined, null, or empty string), because looking up a header without a name is always a programming mistake rather than a runtime condition Express can recover from.","triggerScenarios":"Calling req.get() or req.header() with no argument, or passing a variable that evaluates to undefined/null/'' — e.g. req.get(config.headerName) where headerName was never set, or req.get() during a refactor that dropped the argument.","commonSituations":"Header names sourced from environment variables or config objects that are missing in a deployment environment; destructured options with a typo'd key; code migrated from frameworks where a no-arg call returned all headers. Note Express 4 threw the same error, so this is rarely a version-upgrade issue.","solutions":["Pass an explicit header name string, e.g. req.get('content-type').","Trace where the argument comes from and guard against the config value being undefined (fail fast at startup if a required header name isn't configured).","If you want all headers, use req.headers directly instead of req.get()."],"exampleFix":"// before\nconst auth = req.get(process.env.AUTH_HEADER); // AUTH_HEADER unset -> undefined\n// after\nconst headerName = process.env.AUTH_HEADER;\nif (!headerName) throw new Error('AUTH_HEADER env var is required');\nconst auth = req.get(headerName);","handlingStrategy":"validation","validationCode":"if (headerName === undefined || headerName === null) {\n  throw new Error('header name is required before calling req.get');\n}\nconst value = req.get(headerName);","typeGuard":"function hasHeaderName(name) {\n  return name !== undefined && name !== null;\n}","tryCatchPattern":"try {\n  const value = req.get(headerName);\n} catch (err) {\n  if (/name argument is required/.test(err.message)) {\n    // caller passed undefined/null — fix the call site\n  }\n  throw err;\n}","preventionTips":["Never pass a variable to req.get() without checking it is defined — undefined header names usually come from optional config or destructuring typos.","Use a constant for header names (e.g. const HDR_AUTH = 'authorization') instead of building them dynamically.","Add a lint rule or wrapper helper that asserts the header name is present before delegating to req.get."],"tags":["express","http-headers","typeerror","request"],"analyzedSha":"a3714473feb3d2908add734d340e7755fd85e0a3","analyzedAt":"2026-07-31T18:55:36.968Z","schemaVersion":2}