{"id":17472619,"url":"https://github.com/shinnn/load-gh-token","last_synced_at":"2026-05-14T23:35:02.613Z","repository":{"id":30991234,"uuid":"34549572","full_name":"shinnn/load-gh-token","owner":"shinnn","description":"Get a GitHub access token from either an environment variable or a file","archived":false,"fork":false,"pushed_at":"2019-06-06T22:43:02.000Z","size":41,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-08T22:22:12.571Z","etag":null,"topics":["access-token","configuration","environment-variables","github-api","javascript","nodejs","secret-management","security","token"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/shinnn.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}},"created_at":"2015-04-25T01:06:10.000Z","updated_at":"2024-07-01T19:26:01.000Z","dependencies_parsed_at":"2022-08-26T15:22:01.916Z","dependency_job_id":null,"html_url":"https://github.com/shinnn/load-gh-token","commit_stats":null,"previous_names":["shinnn/eslintrc-node"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/shinnn/load-gh-token","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fload-gh-token","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fload-gh-token/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fload-gh-token/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fload-gh-token/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shinnn","download_url":"https://codeload.github.com/shinnn/load-gh-token/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shinnn%2Fload-gh-token/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271242244,"owners_count":24725004,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-19T02:00:09.176Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["access-token","configuration","environment-variables","github-api","javascript","nodejs","secret-management","security","token"],"created_at":"2024-10-18T17:29:08.966Z","updated_at":"2026-05-14T23:34:57.582Z","avatar_url":"https://github.com/shinnn.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# load-gh-token\n\n[![npm version](https://img.shields.io/npm/v/load-gh-token.svg)](https://www.npmjs.com/package/load-gh-token)\n[![Build Status](https://travis-ci.com/shinnn/load-gh-token.svg?branch=master)](https://travis-ci.com/shinnn/load-gh-token)\n[![codecov](https://codecov.io/gh/shinnn/load-gh-token/branch/master/graph/badge.svg)](https://codecov.io/gh/shinnn/load-gh-token)\n\nGet a [GitHub access token](https://help.github.com/en/articles/creating-a-personal-access-token-for-the-command-line) from either an environment variable or a file\n\n```javascript\nconst loadGhToken = require('load-gh-token');\n\n// When `process.env.GITHUB_TOKEN === '36fae5325faa9b32edfd776f6b85bf71ac0a49bf'`\n\n(async () =\u003e {\n  const token = await loadGhToken(); //=\u003e '36fae5325faa9b32edfd776f6b85bf71ac0a49bf'\n})();\n```\n\n## Installation\n\n[Use](https://docs.npmjs.com/cli/install) [npm](https://docs.npmjs.com/about-npm/).\n\n```\nnpm install load-gh-token\n```\n\n## API\n\n```javascript\nconst loadGhToken = require('load-gh-token');\n```\n\n### loadGhToken([*options*])\n\n*options*: `Object`  \nReturn: `Promise\u003cstring\u003e`\n\nIf there is an environment variable `GITHUB_TOKEN`, it reads its value.\n\nIf the variable `GITHUB_TOKEN` is not defined, then it reads a file `github-token.txt` at the current working directory.\n\n```javascript\n// When `process.env.GITHUB_TOKEN` is undefined but a file ./github-token.txt exists\n\n(async () =\u003e {\n  const token = await loadGhToken();\n  // '... contents of github-token.txt without whitespaces ...'\n})();\n```\n\nIf both the `GITHUB_TOKEN` environment variable and the file `./github-token.txt` don't exist, the `Promise` will be rejected.\n\n```javascript\n(async () =\u003e {\n  try {\n    await loadGhToken();\n  } catch (err) {\n    err.message;\n    // Tried to get a personal access token for GitHub API from the `GITHUB_TOKEN` environment variable or a file at '/Users/example/github-token.txt', but neither exists.\n\n    err.code;\n    //=\u003e 'ERR_NO_GITHUB_TOKEN'\n  }\n})();\n```\n\n## License\n\n[ISC License](./LICENSE) © 2018 - 2019 Watanabe Shinnosuke\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnn%2Fload-gh-token","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshinnn%2Fload-gh-token","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshinnn%2Fload-gh-token/lists"}