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). Dependencies are packages/programs that your program needs to run. For example, Mocha is a dependency that is required for any project that runs Mocha tests. 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. The readings start with how to create a project with npm, something you don't need to do yet. There will also probably be elements that don't make sense right now. Don't worry about that: you won't be tested on these readings, and you can always come back to them later. But for those who are interested, they will explain things like what npm install or npm test does, what those package.json and package-lock.json files are doing in your directory, and how worried you need to be about all those "vulnerability" warnings that appear whenever you install your projects (hint: you don't need to worry).
This first reading covers initialization.
To initialize an app/program 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 these 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.