Update package-lock.json without `npm install` - node.js

I use symlinks in the node_modules directory for local development.
And I use package-lock.json when pushing to Heroku/Dokku.
When updating the dependencies, I want to update package-lock.json without removing my symlinks and running npm install.
Is there a recommended way to achieve this?
Otherwise, I'll just write a script that does git checkout and runs npm install on a temporary branch, before pushing.

Related

package-lock.json is rewritten after npm install

I was working on a react project.
I cloned it in a new machine.
As soon as I ran the command npm install, package-lock.json file was rewritten completely.
Is this a problem?
And how should I deal with it?
npm install can rewrite package-lock.json file. Probably you have dependencies with not fixed version '~x.x.x' or '^x.x.x'. If you already have package-lock.json and want install packages without update lock file, you can use npm ci. See this doc

Npm remove test folders for production

npm prune --production removes packages from devDependencies. Is there any way to it also delete project folders that I do not want in production, such as my "spec" testing folder?
According to the docs, npm prune is used to mantain node_modules clean of extraneous packages, with the added functionality of removing dev dependencies when switching to production, so no, it doesn't seem configurable to perform such a task.
You could define a custom script in your package.json that will delete the folders and invoke npm prune after.

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.

Create package.json from package-lock.json

I downloaded a theme and it has a package-lock.json file but no package.json file.
Is there a way I can generate the package.json from the package-lock.json file.
How do I install the node modules with just the package-lock.json file.
Is there a way to do that?
Warning: Do not attempt before reading comments below & backup package-lock.json.
Install the latest npm with npm install -g npm
Run npm init and respond to the questions.
The above command will generate a package.json and include the existing packages listed in package-lock.json
I think I figured it out.
I don't think npm init can draw from package-lock.json. However it does seem to pull from what is already in your /node_modules. I believe this is why #Harry B's solution works for some and not at all for others.
For example, if you have just cloned your project which contains package-lock.json, no package.json, and empty/non-existence node_modules, npm init won't create any dependencies. However, if you run npm install pkg1 pkg2 pkg3 ... then run npm init it will create the dependencies in package.json.
https://pravnyadv.github.io/unpackage/ seems to work. Copy your package lock file text in, hit the button, copy out the text into a new package.json file.
package-lock.json file relies on the presence of a package.json file, So it's not possible to retrieve package.json (happy to be proved wrong).
So a possible solution left is to use a module like auto-install which is capable of generating package.json from the project file dependencies.
First, you need to install the module globally npm install -g auto-install. Then run npm init and answer the basic requirements.
Then, run auto-install in your project root directory. All the dependencies should reflect in package.json file.
**
Or Install node modules directly from package-lock.json
**
Run npm ci which bypasses a package’s package.json to install modules from a package’s lockfile.
More Information

How do I install all the requirements with npm?

I would like to clone https://github.com/tstringer/create-react-app-with-redux and start a new project. I ran npm start and then ran npm install for each module not present, but there are many of them. Is there a way to install all the requirements? Something like pip install -r requirements.txt in Python.
Thanks,
Uri.
Just run npm install without arguments. It will resolve the required dependencies from the package.json file.
It's simple.
If you want to install all the node_modules from the package.json file you simply put: npm install in terminal (on the same directory where the package.json exists) and it would install all the node modules in the folder called node_modules.
Generally, the node_modules folder is not uploaded in a git (by putting restriction at .gitignore) because it is essentially the same folders or packages that one would have to install, *hence installing it from package.json is simpler and it saves the internet bandwidth and time.
Even you want to save something in the package.json while you are installing any npm package you can simply put npm install --save your-package-name and it would automatically save your package in the .package.json file and you can install the same file, even after you delete the node_modules folder using the same command.
Better yet, if you want to save yourself a lot of time use yarn install instead of npm install (https://yarnpkg.com/en/). It is much faster because it caches everything and operates in parallel (see https://www.sitepoint.com/yarn-vs-npm/ for a good comparison).
npm install githubname/reponame -- Repository Name you can try

Resources