Throughout the JavaScript and React portions of the App Academy curriculum, you
will use Node Package Manager, or npm
, to install and manage JavaScript
dependencies (which are called node modules). npm
is the default package
manager for Node.js; yarn
and pnpm
are examples of other popular package
managers.
This series of readings will explain what npm
does and how you can use it to
manage multiple JS dependencies. This first reading covers initialization.
To initialize an app with NPM, run this command in the app's root directory:
npm init -y
This initialization will create a file called package.json that contains
settings and other information about your app. The -y
(or --yes
) flag tells
NPM to set up the package.json with standard defaults. The end result will
look something like this:
{
"name": "current-directory-name",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
Don't worry about the default settings; they won't affect how your app runs, and you can always adjust them later.
If you leave off the -y
flag, then npm init
will ask you to input the values
you want for each of those keys. For what it's worth, you could also construct a
package.json manually, but using NPM's CLI (command line interface) is just
easier.
In the next NPM reading, you will learn how to install packages.