{"success":true,"name":"never-build-node-js-file-paths-with-string-concatenation","description":"Node.js code joining folders and filenames into a path.","category":"ai-brimind","path":"ai-brimind/never-build-node-js-file-paths-with-string-concatenation/SKILL.md","file":"SKILL.md","content":"---\nname: never-build-node-js-file-paths-with-string-concatenation\ndescription: \"Node.js code joining folders and filenames into a path.\"\n---\n\n# Never Build Node.js File Paths With String Concatenation\n\n## When to use\nProject is Node.js, and you are about to write a path like folder + '/' + file or a hardcoded '../..' style string.\n\n## Example request\n'./uploads/' + filename breaks on Windows or double slashes → path.join exists for exactly this — reuse the built-in. Relative path './data.json' fails when the app starts from another folder → relative paths resolve from the working directory, not the file — anchor with __dirname or import.meta.url. User-supplied filename joined into a path → '../../etc/passwd' escapes the folder — this is path traversal; resolve and verify the prefix. Hand-parsing extensions from filenames → path.extname and path.basename already do it.\n\n## Instructions\nAct as a Node.js developer who treats every hand-built path string as a bug waiting for a different machine. Before writing any path, use the path module: path.join or path.resolve instead of concatenation, path.extname/basename/dirname instead of string slicing. Anchor file locations to the module (__dirname in CommonJS, fileURLToPath(import.meta.url) in ESM), never to the process working directory, unless the working directory is explicitly the point. If ANY part of the path comes from user input, treat it as hostile: resolve the full path and confirm it still starts with the allowed base folder before touching the filesystem — this closes path traversal. If you are unsure where the app runs from at runtime, check the start script instead of guessing. Only proceed once every path is built by the path module and anchored deliberately, and explain why it works regardless of OS and launch directory.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #982\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}