Appearance
Using NPM with RepoForge.io
RepoForge.io provides a powerful platform for hosting private NPM packages, allowing you to manage your Node.js projects with ease. This guide will walk you through setting up your NPM project to work with RepoForge.io, publishing your packages, and configuring authentication.
Setting Up Your NPM Project with RepoForge.io
To get started with using NPM projects in RepoForge.io, you will need to create a new project and configure it to use your RepoForge.io repository. Here are the steps:
- Create a new NPM project:
Begin by creating a new directory for your project and initializing it with NPM:
bash
mkdir myproject && cd myproject
npm init --scope=@repoforge
The --scope=@repoforge
flag scopes your project under the @repoforge
namespace, which helps to organize your private packages and makes it easy to configure access to your RepoForge.io repository.
- Configure your RepoForge.io repository:
Next, configure your NPM project to use your RepoForge.io registry by running the following command. Replace the URL with the specific URL of your RepoForge.io repository:
bash
npm config set @repoforge:registry https://api.repoforge.io/npm/repoforge-hash-id/
This command tells NPM to use the specified RepoForge.io URL for any package published under the @repoforge
scope.
- Authenticate with RepoForge.io using an Access Token:
To authenticate your requests to the RepoForge.io NPM server, you must use an access token generated from the RepoForge.io dashboard. You cannot use a username and password for authentication. The access token must be assigned the "NPM - Full access" role to work correctly.
Set the access token for your project by running:
bash
npm config set //api.repoforge.io/npm/repoforge-hash-id/:_authToken $MY_NPM_ACCESS_TOKEN
Replace $MY_NPM_ACCESS_TOKEN
with your actual access token. This token will be used by NPM to authenticate all requests to the RepoForge.io repository.
- Publish your project to RepoForge.io:
Once the configuration and authentication are set up, you can publish your project to RepoForge.io using:
bash
npm publish
This command will package and upload your project to your private RepoForge.io repository, making it available for you and your team.
Installing NPM Packages from RepoForge.io
To use packages hosted on your private RepoForge.io repository in other projects, you need to ensure that your NPM project is configured to recognize the RepoForge.io registry as a source for scoped packages.
- Add RepoForge.io as a source:
In your other projects, configure NPM to use the RepoForge.io registry for packages under the @repoforge
scope. Run the following command:
bash
npm config set @repoforge:registry https://api.repoforge.io/npm/pMSvTY6/
- Authenticate with RepoForge.io using an Access Token:
Set your access token for the project, ensuring it has at least the "NPM - Read only" role:
bash
npm config set //api.repoforge.io/npm/pMSvTY6/:_authToken $MY_NPM_ACCESS_TOKEN
- Install a package from RepoForge.io:
You can now install packages from your RepoForge.io repository using NPM:
bash
npm install @repoforge/package-name
Replace @repoforge/package-name
with the actual package name you want to install from your RepoForge.io repository.
Further note about authentication
It's also possible to pull NPM projects without auth by making them public, or control access more strictly by enabling package-level permissions. Refer to Authentication and permissions for more information.