{"id":21126153,"url":"https://github.com/mitsuki31/temppath","last_synced_at":"2026-02-07T06:31:56.590Z","repository":{"id":208872104,"uuid":"722686480","full_name":"mitsuki31/temppath","owner":"mitsuki31","description":"Multi-platform temporary directories and files generator","archived":false,"fork":false,"pushed_at":"2024-07-24T01:51:19.000Z","size":954,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-14T01:38:09.919Z","etag":null,"topics":["api","commonjs","esmodule-node","javascript","nodejs"],"latest_commit_sha":null,"homepage":"https://mitsuki31.github.io/temppath/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mitsuki31.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-11-23T17:41:25.000Z","updated_at":"2024-07-24T01:51:00.000Z","dependencies_parsed_at":"2023-11-23T18:39:09.473Z","dependency_job_id":"bd8c19d6-bcd6-4407-a3e9-ffbf8767c1d0","html_url":"https://github.com/mitsuki31/temppath","commit_stats":null,"previous_names":["mitsuki31/temppath"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/mitsuki31/temppath","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitsuki31%2Ftemppath","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitsuki31%2Ftemppath/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitsuki31%2Ftemppath/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitsuki31%2Ftemppath/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mitsuki31","download_url":"https://codeload.github.com/mitsuki31/temppath/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mitsuki31%2Ftemppath/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29188226,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-07T05:07:31.176Z","status":"ssl_error","status_checked_at":"2026-02-07T05:06:15.227Z","response_time":63,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api","commonjs","esmodule-node","javascript","nodejs"],"created_at":"2024-11-20T04:39:29.446Z","updated_at":"2026-02-07T06:31:56.576Z","avatar_url":"https://github.com/mitsuki31.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# temppath\n\nA lightweight and multi-platform Node.js module designed to create temporary files\nand directories. It can utilize the system's default temporary path or a user-specified\ndirectory, offering flexibility and ease of use across different environments.\n\nThis module leverages system environment variables to determine the temporary directory\nand will fallback to the built-in function [`os.tmpdir()`](https://nodejs.org/api/os.html#os_os_tmpdir)\nif the module is incapable to determine the temporary directory provided by the system.\n\nHere’s a detailed example demonstrating how to create a temporary directory using this module:\n\n```javascript\nconst temppath = require('@mitsuki31/temppath');\n\ntemppath.createTempPath((err, tempDir) =\u003e {\n  if (err) console.error('Error creating temporary directory:', err);\n  else console.log('Created temporary directory:', tempDir);\n});\n```\n\nAnd here’s how you can create a temporary file:\n\n```javascript\nconst temppath = require('@mitsuki31/temppath');\n\ntemppath.createTempPath({ asFile: true }, (err, tempFile) =\u003e {\n  if (err) console.error('Error creating temporary file:', err);\n  else console.log('Created temporary file:', tempFile);\n});\n```\n\nIn the examples above:\n- The first snippet creates a temporary directory within the system's default temporary path.\n- The second snippet creates a temporary file within the same system-based temporary path.\n\nIt's that simple! With just a few lines of code, `temppath` allows you to handle temporary\nfile and directory creation effortlessly.\n\nIf you don't like callback-based function and want the `createTempPath` function as a\npromise-based function. Try to promisify it using `util.promisify` function, like this:\n\n```javascript\nconst { promisify } = require('node:util');\nconst temppath = require('@mitsuki31/temppath');\n// Promisify the function\nconst createTempPath = promisify(temppath.createTempPath);\n\n(async () =\u003e {  // Need this block if use CommonJS module\n  // Create a temporary file in current directory with extension '.foo' and\n  // limit the maximum file name's length to 20 characters\n  const tempFile = await createTempPath('.', {\n    asFile: true,\n    ext: 'foo',\n    maxLen: 20\n  });\n  console.log(tempFile);\n  // Output: b3du3b2156sb36bo9hgi.foo\n})();\n```\n\n## About System Temporary Directory\n\nOn different operating systems, the path to the temporary directory is specified by\nvarious environment variables. These paths are used by the operating system and\napplications to store temporary files. Below are the details for each operating system:\n\n### Linux and macOS\n\nOn Linux and macOS systems, the temporary directory path is provided by the environment\nvariable `TMPDIR`. This variable is widely recognized and used by applications for\ntemporary storage. If `TMPDIR` is not set, applications may fallback to using standard\ndirectories such as `/tmp`.\n\nYou can check the temporary path provided by the system echoing the `TMPDIR` environment variable:\n```bash\necho $TMPDIR\n```\n\n### Windows\n\nOn Windows systems, there are two primary environment variables that typically store\nthe path to the temporary directory: `TEMP` and `TMP`. Both variables usually point\nto the same directory and are used interchangeably by the operating system and\napplications to store temporary files.\n\nYou can check the temporary path provided by the system using this command:\n```pwsh\necho $env:TMP\necho $env:TEMP\n```\n\nIf you're using Command Prompt try this instead:\n```cmd\necho %TMP%\necho %TEMP%\n```\n\nIn summary, these environment variables ensure that temporary files are stored in a standard\nlocation that can be easily accessed and cleaned up by the system or applications.\n\n## APIs\n\n\u003ch3 id=\"getTempPath\"\u003e\u003c!-- Need some newlines --\u003e\n\n`getTempPath` (Function)\u003c/h3\u003e\n\n```ts\nfunction getTempPath(tmpdir?: string, maxLen?: number = 32): string\n```\n\nGenerates a temporary path based on the provided or system temporary directory.\n\nThis function utilizes a random UUID for the directory name, ensuring that each time\nit is called, the path will be different from previous calls. The returned path can be\nused for either a temporary file or directory, according to your preferences.\n\n#### Parameters\n\n| Name | Type | Description |\n| ---- | ---- | ----------- |\n| `tmpdir` | `string` | The temporary directory to be used. If not provided or empty, it defaults to the system's temporary directory. |\n| `maxLen` | `number` | The maximum characters' length of the generated temporary path. |\n\n#### Returns\n\nA string representing a generated temporary path with a random UUID that can be used\nas temporary file or directory name.\n\n**Type:** `string`\n\n#### Throws\n\n- `TypeError`  \n  Throws a `TypeError` if the provided `tmpdir` is not a string.\n\n- `RangeError`  \n  If the given `maxLen` is less than or equal to zero.\n\n### `createTempPath` (Function)\n\n```ts\nfunction createTempPath(\n  tmpdir?: string | TempPathOptions | CreateTempPathCallback,\n  options?: TempPathOptions | CreateTempPathCallback,\n  callback: CreateTempPathCallback\n): void\n```\n\nAsynchronously creates a temporary path, either as a directory or file,\nbased on the provided or system temporary directory.\n\nThis function utilizes the [getTempPath](#getTempPath) function.\n\n#### Parameters\n\n| Name | Type | Description |\n| ---- | ---- | ----------- |\n| `tmpdir` | `string` \\| [`TempPathOptions`] \\| [`CreateTempPathCallback`] | The temporary directory path. If an object is provided, it is treated as the `options` parameter. If a function is provided, it is treated as the `callback` parameter, and `tmpdir` will fallback to the temporary directory provided by the system. |\n| `options` | [`TempPathOptions`] \\| [`CreateTempPathCallback`] | Options for creating the temporary path. If a function is provided, it is treated as the `callback` parameter, and `options` is set to `{}` (an empty object). |\n| `callback` | [`CreateTempPathCallback`] | A callback function to handle the result path or error. This is crucial and required, even when you wanted to omit all arguments.\n\n#### Throws\n\n- `TypeError`  \n  If the given arguments or the extension name specified with incorrect type.\n\n### `createTempPathSync` (Function)\n\n```ts\nfunction createTempPathSync(\n  tmpdir?: string | TempPathOptions,\n  options?: TempPathOptions\n): string\n```\n\nSynchronously creates a temporary path, either as a directory or file, based on the provided or system temporary directory\nand then returns a path that refers to the generated temporary directory or file.\n\nThis function utilizes the [getTempPath](#getTempPath) function.\n\n#### Parameters\n\n| Name | Type | Description |\n| ---- | ---- | ----------- |\n| `tmpdir` | `string` \\| [`TempPathOptions`] \\| [`CreateTempPathCallback`] |  The temporary directory path. If an object is provided, it is treated as the `options` parameter, and `tmpdir` will fallback to the temporary directory provided by the system. |\n| `options` | [`TempPathOptions`] \\| [`CreateTempPathCallback`] | Options for creating the temporary path. |\n\n#### Returns\n\nA string representating the path of the created temporary directory or file.\n\n**Type:** `string`\n\n#### Throws\n\n- `TypeError`  \n  If the given arguments or the extension name specified with incorrect type.\n\n- `Error`  \n  Throws an `Error` if there is an issue creating the temporary directory or file.\n\n\n## Development\n\n### Initialize and Install Dependencies\n\n```bash\nnpm install\n```\n\n### Build JSDoc\n\nGenerated JSDocs will be in `docs` directory.\n\n```bash\nnpm run build:docs\n```\n\n### Test\n\nTests are written using inbuilt `node:assert` module.\n\n```bash\nnpm test\n```\n\nAlternatively, you can run each test manually.\n\n- Run CommonJS test.\n  ```bash\n  npm run test:cjs\n  ```\n\n- Run ESModule test.\n  ```bash\n  npm run test:esm\n  ```\n\n## License\n\nThis project is licensed under the MIT License. For more details, see the [**LICENSE**](https://github.com/mitsuki31/temppath/blob/master/LICENSE) file.\n\n\u003c!-- ::: Links ::: --\u003e\n\n[`TempPathOptions`]: https://mitsuki31.github.io/temppath/global.html#TempPathOptions\n[`CreateTempPathCallback`]: https://mitsuki31.github.io/temppath/global.html#CreateTempPathCallback\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitsuki31%2Ftemppath","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmitsuki31%2Ftemppath","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmitsuki31%2Ftemppath/lists"}