Definitions

Module

set of functions, types, classes under a common module/component

Library

set of modules that work together and can be used in another library or program

Package

a distribution unit containing a library and/or an executable. Used to share your code.

“package” and “library” are usually used interchangeably, but this is a more specific definition.

Dependency

when a package depends on another, or when you use a package in your project, that package becomes a dependency

Installing a node package

You can see a list of available packages at npm.

The package.json & package-lock.json

To install packages, you’ll need a package.json and package-lock.json file. To create these files (if they don’t already exist), run npm init -y. The -y flag represents saying “yes” to all prompts (which is fine).

The package.json file stores the names and versions for all installed packages. There are many parts of a package.json but we’re going to be only discussing the important ones. For a full guide, read it here.

Scripts

You can define node scripts to run. Here is an example.

"scripts": {
  "dev": "webpack-dev-server --inline --progress --config build/webpack.dev.conf.js",
  "start": "npm run dev",
  "unit": "jest --config test/unit/jest.conf.js --coverage",
  "test": "npm run unit",
  "lint": "eslint --ext .js,.vue src test/unit",
  "build": "node build/build.js"
}

The scripts are usually to build and start your application, but there can be all kind of scripts related to your application. To run a script, run npm run [script name] (e.g. npm run start).

Dependencies

An installed package is a “dependency” since your project now depends on that package. Here is what is looks like in a package.json

"dependencies": {
	"axios": "^0.27.2",
  "react": "^18.1.0",
  "react-dom": "^18.1.0",
  "react-redux": "^8.0.1",
}