i have created a project using npm init and i created a .npmrc file with some config. when i check the npm config list i am getting project config and userconfig.
do i need to remove the userconfig , but i am not able to edit the file.
i am not understanding why we need the .npmrc file , when you hit a command npm install express , all the config is done in the npm config file ?
how to edit the .npmrc global file in ubuntu ?
do we need to remove the userconfig if we need to use project config ? or its something like which ever comes it takes that
By Searching , i found some infos
when you install npm you have a global config file, whenever you need to access the global config file you can just add -g command
example : npm config list -g
for every projects you can create a .npmrc file, in that file you can configure and you will have private kind of stuff like the packages which are hosted private
so for that you need to create a .npmrc file , if you check npm config list you will have both configs (.npmrc in project folder) and (.npmrc in global)
so its like first it will check with the config in the project folder, if there is no config for project folder it will check for the global config(userconfig)
no need to remove the global config , it will take first comes first serve so the project folder config will be taken if its there otherwise only it will check for the global config
Editing the Global config file
you can edit the global config file by going to
cd /
cd home/"username"/
vi .npmrc
change the file save it by using press esc type :x
Related
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.
For some reason related to the tools I'm using I can't use .npmrc file. There is another way to pass configuration to npm?
I have been using an NPM for angular-4 which support drag and drop objects (ng2-drag-drop). I found a missing functionality and decide to add it to the package.
What I did is forking the original project and adding my changes. after commit/push to my git I then used the following command to install my NPM :
npm install https://github.com/..... --save
the NPM installed successfully however when looking in my node_modules I see that the source files are missing and I have only the root directory including the package.json and some other files . any source files are missing.
I then tried to instal the NPM directly from the author git so instead of running :
npm install ng2-drag-drop --save
I used
npm install https://github.com/ObaidUrRehman/ng2-drag-drop.git --save
and I had the same issue with my fork.
Why the installation is different between the author git and the named package ? isn't it taking the files from the same location ? if no, what should I do to make it work ?
The reason you are not able to see the src folder is
If you see the git repo you will find two files
gitignore & npmignore.
In that npm ignore file you will find the src has been ignored to be prevent it from being added to the package when running npm commands .
Keeping files out of your package
Use a .npmignore file to keep stuff out of your package. If there's no
.npmignore file, but there is a .gitignore file, then npm will ignore
the stuff matched by the .gitignore file. If you want to include
something that is excluded by your .gitignore file, you can create an
empty .npmignore file to override it. Like git, npm looks for
.npmignore and .gitignore files in all subdirectories of your package,
not only the root directory.
You need to overwrite these settings to be able to get src contents in node modules when you do npm install
I am trying to install Bower globally and it is installed in the directory of
C:\Users\{{user}}\AppData\Roaming\npm\node_modules\bower
I have added the system path of Path and NODE_PATH to that of above, however when running bower, it still cant find the modules.
the prefix of npm-config is:
C:\Users\{{user}}\AppData\Roaming\npm
however later within the the list it states it as
"C:\Program Files (x86)\nodejs" (overridden)
Ive run out of ideas of what it could be,
If you using npm, which looks like you are, then use the global flag (run as admin)
npm install -g bower
Sometimes another version or just a wrong path is referenced in the npm config file instead of the installed version.
This may cause node/npm to misplace global modules.
To check and fix:
In cmd line type: npm config list
You should get a list of configuration values, one of them is prefix.
Make sure the path in prefix is the same path (only without node.exe) as the actually installed node.exe path.
(this path is listed further down as node bin location)
If it's not, change it:
Either in the config file (in your user folder, named .npmrc)
Or, via cmd line: npm config set prefix "C:\Program Files\nodejs" (change path if needed)
Reinstall the module/package you tried to install, don't forget -g for global.
I am hoping to run npm config to set values in a project's .npmrc file.
Docs dont seem to say how to specify a file to save the values into.
Looking for something like
npm config --file /path/to/repo/.npmrc set key value
Trying to use it for a build script that needs to build a .npmrc file from env vars.
It is baffling that this is seemingly still not directly supported as of npm v6.9.0.
It's a bit awkward, but if your npm version is recent enough, you can repurpose the --userconfig option to make npm config operate on a project-specific .npmrc file.
E.g., from a given project's root folder, the following command project-locally configures pwsh (PowerShell Core) as the shell to run scripts with, by making npm config operate on the local .npmrc file via --userconfig:
# Updates .npmrc in current dir
npm config set script-shell pwsh --userconfig .npmrc
Note: As Kerry Johnson points out:
The target file is rewritten as a whole, in the course of which any comments (#-prefixed lines) in the original file are lost (but all key-value pairs are preserved).
The config keyword is optional in this case, so the following will do:
npm set script-shell pwsh --userconfig .npmrc
You can do a chroot, build your config file on ~/.npmrc and then copy it on the right location.
you can override any property which could be set by the .npmrc
by passing it through command line.
For example --package-lock false will turn off package-lock generation.