npm and the JavaScript Toolchain package.json Is the Project's Identity Card
1 / 5
Next
package.json Is the Project's Identity Card ~15min

Start a project

npm init -y

That creates package.json, the file that describes your project and everything it needs.

{
  "name": "merik-site",
  "version": "1.0.0",
  "scripts": {
    "dev": "vite",
    "build": "vite build"
  },
  "dependencies": { "axios": "^1.6.0" },
  "devDependencies": { "vite": "^5.0.0" }
}

dependencies versus devDependencies

  • dependencies, needed for the code to RUN
  • devDependencies. Only needed to BUILD or test it

Put a build tool in dependencies and your production install becomes needlessly large. npm install --omit=dev on a server installs only what actually runs.

Scripts

npm run build

A script can call any binary in node_modules/.bin without a global install. This is why a project can be cloned and built by anyone with the same commands, on any machine.

Commit package.json

Always. It is how another person (or a deployment) reconstructs the project.

Tasks
Preview