npm - askbid-notes/notes-react GitHub Wiki

$ npm init
$ npm install <package_name>  #inserts dependency in package.json
$ npm install                 #install dependencies creating /node_modules folder
$ npm test
$ npm start                   #starts a server to run the react app on


The package.json file tells you (and npm) everything about what packages are required for a specific JavaScript application, listing out each package name.

When we run the command npm install in a directory where a package.json file is present, npm reads the names of each dependency from the package.json file and downloads the packages from npmjs.com, where they are hosted. It then begins installing those packages - BUT! those packages also have their own package.json with their own dependencies! npm must also get those packages, and if those packages have any dependencies, get them as well. So on and so on. This is what we refer to as a dependency tree.

If you are working in a local environment running npm install creates a folder called node_modules, which contains all the downloaded packages.

If you need some specific package. We can install packages by running npm install <package_name> while inside a project directory.

A Little More on package.json

npm init

Since npm relies on a package.json file, it has a built in command to build package.json files. Running npm init on the command line will begin a series of prompts, asking about specific content to include in the file. At the end, it will create a file or edit an existing package.json file. Very handy when you are creating your own projects from scratch!

npx and create-react-app

npm install -g npm

This will make sure you have the newest version of Node Package Manager. It will also give us access to npx. with npx, we can provide a node package name as an argument and use remote node packages as though they were installed with npm.

npx create-react-app <your_app_name>