All about npm
ANYWAYS WOW… npm comes with node.js, so as long as you have node.js installed, you’re good to go. https://nodejs.org/en/ to dl
Check your npm version
$ npm -v
Upgrade your npm version to the latest version (note: this may take a while and you will receive very little feedback that it is actually doing anything)
$ npm install -g npm
Check version of an npm package globally
$ npm list -g babel
Check version of an npm package local
$ npm list $ npm list <package_name> $ npm list react
Get all possible versions available on NPM for a package
Find out where node modules are installed globally
$ npm root
Find out which packages are installed globally
$ npm list -g
Remove extraneous packages npm
$ npm prune
Create a new node.js project… at least I’m pretty sure that’s what this does…
$ npm init
Install a dependency for your application across development and production and update package.json (this is completely local to your project)
$ npm install react react-dom --save
Install a node package available for all npm projects (people recommend you do this sparingly)
$ npm install -g my-package
What the fuck is the difference between a dev-dependency and a dependency in package.json
Well, here’s a good resource. http://stackoverflow.com/questions/18875674/whats-the-difference-between-dependencies-devdependencies-and-peerdependencies . The short answer is
devDependencies are used to write code. They do stuff like compile and build code.
npm install –production will not install devDependencies.
NPM ERRORS or WARNINGS that I’ve experienced
ERROR: $ npm install npm WARN email@example.com requires a peer of webpack@1 || ^2.1.0-beta but none was installed.
Yea, that makes absolutely no fucking sense. But… here’s the solution… Basically npm wants you to declare a peer dependency explicitly in your
package.json (I had webpack installed globally). So to fix the error simply run.
Solution: $ npm i webpack –save-dev
Here’s what spawned node package manager (in my head, may have no relevance to any truth at all). People were developing all these packages for node. Sometimes when you create a package, it depends upon another package. A lot of times, you write some code, and you can use code from other people. But instead of asking you to figure out the dependencies yourself, node package manager does it for you! So node package manager really manages the dependencies of your application. I wish I could give you a concrete example, I mean, I could do that, but I don’t feel like it… so I’m going to be a shithole tutorial writer and not give you something that would actually really help you. This is what other tutorial writers do, they just don’t tell you they’re doing it. They aren’t technically lying to you because they didn’t say anything about being lazy, they just aren’t being forthcoming with the truth.