Setting up GitHub Personal Access Tokens for local development
Private NPM Package Requirements
In order to utilize your private GitHub NPM package you're going to need two things:
- A GitHub Personal Access token setup and configured for your local machine (steps below)
- A new file:
.npmrc
which will live right next to yourpackage.json
in your project repo (the codebase you're implementing your design system in). The exact file contents below:
@knapsack-cloud:registry=https://npm.pkg.github.com/ //npm.pkg.github.com/:_authToken=${GITHUB_TOKEN}
Generating and verifying your GitHub token
- You will need to add an env variable of
$GITHUB_TOKEN
in order to install your private NPM package@knapsack-cloud/[YOUR-PRIVATE-PACKAGE]
in your project. - If you run
echo $GITHUB_TOKEN
and do not see anything — you haven't setup your env variable. Proceed to next steps below. - While logged into GitHub, visit your account tokens page —> create a new token
- The only permission required is
read:packages
- Proceed to the sections below to store your token
Mac
- Add
export GITHUB_TOKEN="[TOKEN HERE]"
(no square brackets or quotes) inside either your.bash_profile
,.bashrc
, or.zshrc
- Important: You will need to
source
your bash profile afterwards (or completely restart the terminal). - Open a new terminal and run
echo $GITHUB_TOKEN
again —> verify you see your token. - If you do not see your token —> revisit step 2 above.
- Now you can
yarn install
/npm install
🎉
Windows
NOTE: For Windows users, we must add the environmental variable through system configuration screens.
- Open System Environment Variables
- Under the System Properties, navigate to the Advanced tab and click the bottom Environmental Variables button
- Next, in the System variables section — click the New button
- For "Variable name" use "GITHUB_TOKEN" (no quotes)
- For Variable value — paste the token you received from step 3 of the first section above.
- Click OK
- Important: restart your computer
- When the system comes back up – open Windows PowerShell and type this command:
$env:GITHUB_TOKEN
— you should see your personal access token! - Now you can
yarn install
/npm install
🎉