Can I copy the remote folder of node mudules on git lab? - node.js

The node module that I need has been updated, and there is an old version of it installed on the gitlab project. Is it possible to get the folder for that specific module as it is when it was installed?
Thank you

You dont't want to keep source code of external dependencies in your repo. You should add your node_modules to .gitignore and remove it from the repo. Instead, you just track your dependencies in your package.json file by installing them via npm install --save. Then, when someone checks out your project, he just runs npm install and all dependencies get resolved automatically. If you want to update any of the dependencies, you update it via npm cli, and commit the updated package.json to your repo.

Related

How to switch from default npmjs repo to Artifactory repo in Angular project

I'm developing an Angular application and until now I have been using the default npm repository (registry.npmjs.org). Now I need to switch to using Artifactory and update my project accordingly.
I already changed the registry with:
npm config set registry (myArtifactoryRemoteRepoURL)
Then, after deleting the nodes_module folder I ran the npm install command:
npm i
I also tried:
npm i --package-lock
The modules are still loaded from the default npmjs registry. I guess this is because in the package-lock.json the dependencies are still resolved to default repo URLs. So I would probably have to update the package-lock.json somehow.
You can delete the package-lock.json file entirely (and the node_modules as well). Those will be regenerated when you run npm install.

Is there anything that can keep track of my installed npm packages and restore them on a different dev environment ? (like "Restore NuGet packages")

So I'm new to node/npm packages. Here's the scenario.
I installed all the dependencies on an environment.
Pushed the code to a remote repo
Pulled the code to a different dev environment.
Tried to restore all the previously installed dependencies
automatically but couldn't figure out a way.
I worked with NuGet packages before. I was expecting something similar to the behavior of "Restore NuGet Packages".
I've looked into my packages.json file but they don't list the later installed dependencies like packages.config file would do in case of NuGet. So is there anything similar? or am a missing something?
The package.json file is doing what you are looking for. Installing a dependency with --save option will add it to the package.json dependency list. On another environment you can install same dependencies with running npm install command.
Install a dependency for the first time: npm install newpackage --save
Push the package.json to the repo
Pull the repo
Install all dependencies which listed in package.json file by running npm install command in the directory which package.json reside

Npm Install straight from package.json

I have a simple question that i cant seem to find the answer for. I cloned a git repo to my local machine.
When attempting to start node, I receive an error because i don't have the required npm dependencies installed. However, they are located in the packages.json file that was cloned.
I was wondering if there was a simple way to install the dependencies located in that file, without having to npm install for every individual package.
Within the directory of the package.json file, just run npm install. It will read package.json and install all dependencies. If you want to limit it to only non-dev dependencies, use npm install --only=production.

node_modules folder in an ASP.NET Core MVC project

I've recently upgraded my netcoreapp1.0 to netcoreapp1.1. This left me wit ha few surprises and error that needed to be fixed. On top of that, I recently got a new PC, which forced me to go through even more things.
First up I had to install NodeJS again, and from the node package manager, install bower. After installing both NodeJS and bower, and several hours after working on my project, I realized, as I had to commit the changes to remote source control, that a node_modules folder had appeared (though hidden) in my project. Git of course wants to commit this folder, but I'd rather not since it contains loads of subfolders and other items.
I was wondering what to do with this folder. I believe it shouldn't be there? And I'm not sure why it is. Shouldn't it be global or something, specific from PC to PC? Or should I just add it to my .gitignore file?
Quick info: It wasn't there prior to the upgraded project, meaning that I couldn't see any node_modules folder in netcoreapp1.0 and there's no folder in my source control?
This node_modules folder wasn't there before because before it was installed globally:
npm install -g bower
the advantages of globally installing bower is that you can use the bower command through the command-line directly.
now apparently bower was installed locally, with the following command:
npm install bower
Now it was locally installed in the node_modules folder, meaning this folder appeared.
You don't need to check this folder into get and you can simple add the following rule in your .gitignore file:
node_modules
But 1 thing to remember! when you build your application with teamcity or some other CI build tool you will now need to install npm packages (just run npm install in the folder) before you publish your application, otherwise these javascript files will be missing.

How to edit a node module installed via npm?

I'm using the node_swiz module, which in turn uses the validator module.
I want to make changes to the validator module, but I used npm install to install the modules/dependencies.
Can I just make changes to the validator module inside of node_modules, or will that node_modules dependencies be re-created and the latest version gotten when I publish to heroku or next time I run npm install?
The structure looks like this:
myNodeApplication
- node_modules
- swiz
- node_modules
- validator [this is the library I want to edit]
Thanks for the help!
You can edit the file directly, but this would be overwritten whenever npm updates, the best thing to do is go straight to the source.
If the changes affect functionality of the overall module, and may be useful to others, you may want to contribute to the original source on github and look for the change to be implemented.
If this is proprietary functionality that is needed, and would not help the development of the module, the best thing to do is fork it from github and make your changes. You can install items directly from github using NPM, and this method would let you integrate future changes in to your custom version from the original source.
To install directly from github, use the following command:
npm install https://github.com/<username>/<repository>/tarball/<branch>
You can use patch-package to make and persist changes to node modules.
This can be done by first making changes to the package inside node_modules and then running the following command, with <package name> being the name of the package you just made changes to.
npx patch-package <package name>
patch-package will then create a patches folder with a file inside, representing your changes. This file can then be commited to git, and patches can be restored later by running npx patch-package (without any arguments).
Optional step:
Add the following in the script section of your package.json to automatically patch the dependency when you execute "npm install".
"postinstall": "npx patch-package"
I didn't want to publish a new module and I also didn't want npm install to overwrite my changes. I found a solution to both of these issues, but it would probably be better to take #Sdedelbrock's advice. But if you want to do it, here's how:
Edit your package.json file to remove the dependency you want to edit.
Go into your project's /node_modules and move the folder somewhere else in your repository that can be committed. So now /node_modules/dependency is at /dependency
cd into the dependency directory and type npm link
cd into the root of your project directory and type npm link dependency It is important that you do this outside of /node_modules and /dependency
If everything worked, you should now have a symlink that was created in /node_modules/dependency. Now you can run your project to see if it works.
Fork the Github repo and make the necessary changes then you can install the package like
npm install git+https://github.com/visionmedia/express.git

Resources