How-to With MyGet (NPM-Specific)

Nikhil Kapoor
Jul 22 · 5 min read

What is MyGet?

MyGet allows you to create your own public or private npm registries in just a few clicks and work with your own node modules (packages). This section will guide you through it.

Types of Feeds:

  • Public feed: Everyone can search and download packages from this feed.
  • Community feed: Everyone can search and download packages from this feed. Additionally, any user can push and manage their own packages on this feed.
  • Private feed: Nobody has access to this feed. The owner of the feed can invite the users that are able to access this feed.

Creating a New Feed

  • Browse to MyGet.org (https://www.myget.org) and log in using your preferred identity provider.
  • Complete your new MyGet profile by providing a username and password. These are your MyGet credentials, which you’ll need to authenticate against private feeds on MyGet.org. From now on, you can also use these to log in on the MyGet.org web site.
  • Create a new feed that will serve as a registry and select the desired security template: public, private or community public: everyone has read access, only feed owners/managers can write private: only users with explicitly granted permissions can read or write (depending on permissions) community: everyone can read all packages + anyone can manage the packages they pushed to the feed
  • (optional) Invite collaborators through the feed security

How to publish over MyGet?

For publishing any NPM package, you should have package.json and package-lock.json in your directory.

Package.json file contains important information related to NPM package like Author, Description of the package, Files to include in the package, etc.

Whereas Package-lock.json contains the dependency tree required for the overall project.

Publish with NPM Login

Step 1: Go to your package.json directory using command prompt and type

npm config set registry https://www.myget.org/F/[your-feedname-here]/npm/

this command will set your default registry as NPM to publish the package and for getting this URL you can go to MyGet->yourfeed->Feed Details -> npm and you can copy the feed URL from there.

Step 2: Type NPM login and enter your credentials

Step 3: Type npm and Publish and it is done.

Reference:

Publish with .npmrc

Step 1: Go to your package.json directory and create a new file with name .npmrc

Step 2: Write this code in your file to set registry and credentials

registry=https://www.myget.org/F/your-feed-name/npm/

//www.myget.org/F/your-feed-name/npm/:_password="base64encodedpassword"

//www.myget.org/F/your-feed-name/npm/:username=someuser

//www.myget.org/F/your-feed-name/npm/:email=someuser@example.com

//www.myget.org/F/your-feed-name/npm/:always-auth=true

Replace data with your feed name and credentials

Note: Make sure you convert your credentials to EncodedBase64 else you will get 403 error

Step 3: Type Npm Publish and it’s done

Reference:

In case you want to publish this without human interaction or you don’t want type your credentials.

Publish with AuthKey using .npmrc

Step 1: Go to Package.json directory and open a command prompt.

Step 2: Create .npmrc file with in the same directory and paste

registry=https://www.myget.org/F/your-feed-name/npm/

always-auth=true

//www.myget.org/F/your-feed-name/npm/:_authToken=your-api-key

Step 3: Go to your myGet Account->Feed->Feed Details

Step 4: Copy the API KEY and replace with your-api-key in .npmrc file and your-feed-name with your feed name.

Step 5: Go to command prompt and type npm publish.

Ref:

How to consume npm package from MyGet?

To use the private scoped package from myGet we can use 3 ways as mentioned below

With Npm Login

For consuming the package from myget using npm login follow these steps:

Step 1: Go to your package.json directory using command prompt and type

npm config set registry https://www.myget.org/F/[your-feedname-here]/npm/

this command will set your default registry as NPM.

Step 2: Type npm login and enter your credentials

Step 3: Npm Install package name and it’s done

With Auth Key

Step 1: Go to your package.json directory and type command

npm i packageName@<Version> — registry=https://www.myget.org/F/reg/auth/secretkey/npm

Consume from package.json

If you want to consume this from package.json then you can directly mention the registry URL in your package.json like

“dependencies”: {

“test_package”: https://www.myget.org/F/reg/auth/dd784048-3a66-4d4a-a1c5-5fb5b331fdda/npm/test_package/-/1.0.0.tgz",

}

Step 2: Npm Install and it will automatically install your package form myget

FAQ’s

I am getting 404 for the package that is required by my library. What should I do?

Enable upstream source proxy to seamlessly blend your MyGet feed with the public npm registry. From the Upstream Sources tab, edit the Npmjs.org upstream source and enable the Make all upstream packages available in clients option. If you prefer to have the package binaries downloaded to your feed for subsequent requests, also enable the Automatically add downloaded upstream packages to the current feed (mirror) option.

I have added my test package as a dependency in package.json while running npm install its running fine but when I run npm audit, It throws the error of invalid URL

In order to solve this issue type

npm audit — registry=https://registry.npmjs.org

I am getting package corrupted error while installing it. What should I do?

Make sure that you are pointing main, In your package.json, to the right direction

I don’t want to publish my test folder and source folder. What should I do?

You can either add the file in the .npmignore file that you don’t want in your publish or mentioned the files or folders in a file property of package.json as mentioned below

Using .npmignore

PS: If you don’t add .npmignore it will automatically use the .gitignore file

Using file property

How can I publish the package from bitbucket pipeline?

In the above example, the core is the folder which we want to publish and you can set your variables in bitbucket pipeline in order to secure them

Thank you for reading my article. Like it? Clap it…

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade