Npm and updating the package file

Hi,

Just working away on learning Node and Vuejs. I was wondering what other coders do out there as good practice.

Do you type out the package names and versions you need in the package.json file and then do $npm install or do you just $npm install <packagename> and then adjust the version as needed?

Thanks

npm install <packagename> (or npm install <packagename> -D if it’s a dev dependency), just adjust the version if that is really important (or type it out it it’s a non-npm dependency, eg it comes from Github). npm update to update if necessary. Because NPM packages are by convention very small, you generally need lots of them, so manually typing into the package.json is likely to be error-prone.

1 Like

Thanks DanCouper!

That was the clarification I needed. :beers:

I was typing out a long package file and was wondering if other people just do $npm install <packagename> because it seems faster on top of being more accurate as you said.

npm install saves any specified packages into dependencies by default.

Then you can install a specific version with the @<version> flag.
So for instance:

npm install vue // will install the latest version
nom install vue@1.1.0 // will install the specified version

You can learn all about install and its flags in the manual page.


note:
One thing that I’ve found extremely useful when working in Node is to remove the “compatible version” flag and use the exact match.

If you notice after you install a package, NPM will add the dependency with the
compatible version flag: ^

I generally remove it since has caused issues when working in team, where the dependecies had different versions across different install.

2 Likes

Thanks for the tip! Hope to work in a team sometime soon… That also sounds like the opposite of what compatible means…:laughing: