npm private git or bitbucket module

อยากจะสร้าง common lib ไว้ใช้งานโดยผ่าน git หรือ bitbucket ให้ใส่โค้ดไว้ใน package.json มีให้เลือกหลายวิธีดังนี้

Basic auth

GitHub has support for basic auth:

"dependencies" : {
    "my-module" : "git+https://my_username:my_password@github.com/my_github_account/my_repo.git"
}

As does BitBucket:

"dependencies" : {
    "my-module": "git+https://my_username:my_password@bitbucket.org/my_bitbucket_account/my_repo.git"
}

แต่เราไม่ควรใส่ password ลักษณะนี้ใน package.json

Personal access tokens (GitHub) แนะนำ

To make this answer more up-to-date, I would now suggest using a personal access token on GitHub instead of username/password combo.

You should now use:

"dependencies" : {
    "my-module" : "git+https://<username>:<token>@github.com/my_github_account/my_repo.git"
}

For Github you can generate a new token here:

https://github.com/settings/tokens

App passwords (Bitbucket) แนะนำ

App passwords are primarily intended as a way to provide compatibility with apps that don’t support two-factor authentication, and you can use them for this purpose as well. First, create an app password, then specify your dependency like this:

"dependencies" : {
    "my-module": "git+https://<username>:<app-password>@bitbucket.org/my_bitbucket_account/my_repo.git"
}

[Deprecated] API key for teams (Bitbucket)

For BitBucket you can generate an API Key on the Manage Team page and then use this URL:

"dependencies" : {
    "my-module" : "git+https://<teamname>:<api-key>@bitbucket.org/team_name/repo_name.git"
}

reference https://stackoverflow.com/questions/10869796/npm-private-git-module-on-heroku

Related posts:

This entry was posted in nodejs. Bookmark the permalink.