How to reset the npm registry in global npm config - npm

Is there any way to change or reset the global npm registry.
Appreciate your assistance.

Run the following command in your terminal to revert back to the default regsitry
npm config set registry https://registry.npmjs.org/
or
npm config delete registry
NPM CONFIG DOCS

If you are on windows, other than setting the registry, you can also delete the .npmrc file to reset the registry.
You can find this file at C:\Users\<Your User Name>\.npmrc

Sets a configuration key to a value
npm config set <key> <value> [-g|--global]
Gets the value of an existing configuration key
npm config get <key>
Deletes the key from all configuration files.
npm config delete <key>
Lists all the config settings,could be used to check for existing config entries
npm config list
Opens the config file in an editor.
npm config edit
All that would help make changes to the npm registry
Source
Hope that helps!

Yes...
You can use this
$(npm config get globalconfig)
npm config --global edit

In my experience, I had to use a private NPM registry for security reasons and while switching projects I had to change my registry and found that I was unable to! A requirement of the private registry was to be on a VPN network so to be able to connect to the private registry.
Command I was trying to run
npx sb init --builder webpack5
I was trying to install storybook in an existing project.
I tried and failed by:
npm config set registry https://registry.npmjs.org commands even with --location= set to project, user, global
setting .npmrc with npm_config_registry=https://registry.npmjs.org value in multiple locations
even yarn wouldn't change the registry and I also tried to use the yarn specific commands as well yarn config set ...
restarting my system multiple times and re-trying all of the above in different ways
Information about my environment:
OSX, NVM (Node Version Manager), using npm not yarn
What ended up fixing my problem
2. I ended up reconnecting to the VPN so that when I ran my npx ... command from above it would still download the packages through my private registry
3. rm -rf node_modules package-lock.json I removed the installed files and lockfile
4. I disconnected from my VPN and re-installed packages with the same npx ... command
5. I see now that the packages are properly pulling from https://registry.npmjs.org
For some reason NPM wanted to resolve something from the private registry I had before finally using the newly configured public registry.
Might be a bug with NPM that I do not have the experience nor time to troubleshoot though I wanted to share my experience here in hopes it will help someone with a similar experience.

Related

Yarn lock file resource source changed from registry.yarnpkg.com to registry.npmjs.org

I recently npm installed a package into my Ruby on Rails application. The installation changed my yarn.lock file. Specifically, the "resolved" field for all my resources have changed from yarnpkg.com to npmjs.org.
From this:
d3-dsv#1:
version "..."
resolved "https://registry.yarnpkg.com/d3-dsv/-/d3-dsv-1.0.8.tgz#..."
integrity ...
To this:
"d3-dsv#1":
"integrity" "..."
"resolved" "https://registry.npmjs.org/d3-dsv/-/d3-dsv-1.1.1.tgz"
"version" "..."
Is there a problem with these changes in this yark.lock file? Should I have done some yarn alternate to npm installing?
You can fix this issue by re-running yarn again.
To accomplish this, follow the steps below.
Remove the registry.npmjs.org section in your yarn.lock file.
Run the yarn command again.
$ yarn
This should rewrite the yarn.lock to change the registry from npm to Yarn.
The steps above should rewrite the yarn.lock file, and change the registry and text from npm to Yarn.
If you are using only public packages in your application then this will not cause many problems. You can go about your business as it is.Although there might be some complications when you authenticate for any of them at any point.
If you are using any private repositories, you have to re-register your packages with yarn and add credentials to them.
The following steps will help you.
Setup a private repo on npmjs.org and add a scope and your package (Lets name it boo)
Create a new project locally and upload it to the npm registry (let's call it blimp)
So when they are updated it will be #boo/blimp
Add the package to your new applications package.json by installing yarn add #boo/blimp
Remove the node_modules (rm -rf node_modules)
Try yarn install if there is an error in the lock file try re-creating one as follows
sed -ie 's,registry.yarnpkg.com/#boo,registry.npmjs.org/#boo,' yarn.lock
7. If that omits an issue like Request failed or something in that alley, try following
yarn config set registry https://registry.npmjs.org
At this point, you have tried lots of options. If this is still an issue in your system then you might have to move to `npm` package management. Follow the [yarn][2] repository for more updates.
Similar issues
yarn.lock should not include base registry
Support protocol-relative registry
Support for registry URLs without trailing slash
I suspect this happened to me because I installed something with npm install instead of yarn. I recognized my mistake, npm uninstalled the package, then yarn added the package, but then every entry in yarn.lock was changed to use npmjs.org instead of yarnpkg.com.
I did not commit the changes to source control, and the problem disappeared after I...
Deleted package-lock.json
Reverted the change to package.json in source control (i.e. removed the new package)
Reverted all changes to yarn.lock in source control
yarn added the package again
I am unsure if using npm install followed by yarn add is really what triggered the problem. Can anyone confirm?

npm install always uses artifactory registry and ignores .npmrc file

My .npmrc file previously contained registry=https://company.jfrog.io so upon npm install this registry was used. Now I want to use the public registry for my personal project, but even though I delete the .npmrc file and even create one at the root of my project containing the public registry, this custom registry is always used to install dependencies!
When i run npm config ls -l it displays registry = "https://registry.npmjs.com/" . But when i remove the lockfile and npm install, it still uses the artifactory registry!
How can I just use the public npm registry?
If you change from one registry to an other you need to make sure, that you do following things:
Check the current registry with npm config list command. The command should be called from the root directory of the project, as a local .npmrc can overwrite the registry settings. If the listed registry entry is not ok, please update the global and/or the local .npmrc file.
Delete node_modules in your project.
Remove package-lock.json in your project.
Clean the npm cache by deleting the npm-cache folder manually. On Windows it is by default on %appdata%\npm-cache location. As an alternative npm cache clean --force command could also work, but if you want to be sure, do the manual delete.
In your case most probably the last step is missing, the cleaning of the npm cache. If the npm cache is not cleaned, npm install gets the already downloaded packages from the cache and writes their registry url into the newly generated package-lock.json. And as the cached packages are still from https://company.jfrog.io, the urls in the generated package-lock.json will still point to https://company.jfrog.io.

How can I remove the npm registry from my machine?

I published a module to npm. When I uninstall it and try to reinstall it, this is always done from a cache ( it is done even if I'm not connected to the internet, I just get a warning ). I would like to try if my module installs correctly from the remote npm repository on a fresh npm registry.
I tried to remove Node.js and reinstall it, but it does not help. There is no "npm" in the list of my applications that I could remove, only Node.js is listed. This is on a Windows 10 machine.
Where is the npm registry located and how can I remove it entirely?
You have to clean your NPM cache and then clear your registry using the below commands.
npm cache clean
npm config delete registry
Thanks
npm config delete registry
This worked for me

How to use yarn with private npm registry in Sonatyoe Nexus OSS?

I ve setup the nexus oss 3 and it looks cool. All my projects are installed by using yarn because of the --pure-lockfile option.
Steps to reproduce the issue:
1. Setup nexus oss 3 with a private npm registry (as in documentation)
2. Disable anonymous access from nexus oss 3 admin panel
3. On a linux server with alpine try to yarn install --pure-lockfile (you must have a package that is hosted on the private repo in package.json)
4. Does not work, return 401 error
I tried everything but i could not manage to make yarn to login to get those packages.
If i use npm install, it works.
Can someone tell me how to make yarn work nexus oss3 using the setup from above?
If npm install is working, then you must have login credentials and repository correctly defined.
Open terminal and run npm login, give your username and password for nexus account. This will create a file ~/.npmrc. Open this file nano ~/.npmrc, output look like
//<repository>:_authToken=NpmToken.<token>
A dummy example:
//test.server.com/repository/npm-group/:_authToken=NpmToken.123456-12345-12345-tok-en0onum
Go to the project directory cd <project_dir>, create a new file .yarnrc, open it nano .yarnrc. Insert the following line, save and exit (Ctrl+O, Ctrl+X) it.
registry "<repository>"
Create another file .npmrc in the same directory <project_dir>. Open, add the following line, save and exsit.
registry=<repository>
always-auth=true
//<repository>:_authToken=NpmToken.<token>
Delete the .npmrc at home directory rm ~/.npmrc.
Now you can download node_modules with yarn or yarn install.
I had same issue with nexus 3 and use this configuration on my .npmrc file:
registry=https://your.nexus.com/repository/some-npm/
always-auth=true
/* basic-auth-token: your user:password in base64 */
_auth=<basic-auth-token>
Hope this help you!
The fact that your requests returns 401 (Unauthorized) means that you should supply credentials when connecting to Nexus.
It is far from being a nice solution but I got it working using
yarn set registry https://user:pwd#your.nexus.host/nexus3/repository/npmjs/
I use yarn 1.4.0 (release candidate). It should also work on 1.3.2, but I cannot test that because 1.3.2 has issues with HTTPS_PROXY env vars.

how can i get scoped npm packages form artifactory

I have a problem with pulling scoped packages from artifactory remote repository
I have watched item : [Installing scoped npm packages from Artifactory
my virtual repository name is swm-virtual-npm
I did a :
npm config set registry http://server:8080/artifactory/swm-virtual-npm
npm install #angular/core
and it fails. when I do it with gulp package it works.
I have added the org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH = true flag.
the data the request.log gives me is :
20170329113552|12|REQUEST|10.82.72.231|anonymous|GET|/swm-virtual-npm/#angular%2fcore|HTTP/1.1|302|0 20170329113552|0|REQUEST|10.82.72.231|anonymous|GET|/ui/nativeBrowser|HTTP/1.1|406|0 20170329113552|1|REQUEST|10.82.72.231|anonymous|GET|/swm-virtual-npm/#angular%2fcore/|HTTP/1.1|406|0
The problem is quite simple, you are missing the required api/npm in the URL. It should be:
npm config set registry http://server:8080/artifactory/api/npm/swm-virtual-npm
Your ~/.npmrc should look something like this:
registry=http://server:8080/artifactory/api/npm/swm-virtual-npm
_auth = ......
always-auth = true
You may want to delete all the content in your NPM remote repository caches (if there are any in what I assume is a virtual NPM repository). It is likely your attempts to access it without api/npm may have corrupted the cache.