liveBook · Manning

Npm install

As explained in Road to Kubernetes

npm install is an npm command that installs project dependencies declared by a Node.js package.

npm install installs the dependencies declared by a Node.js project, allowing an Express.js application to run locally, after deployment, or inside a container. section 3.4.2 section 5.4

Use npm install as part of a repeatable application setup:

  • Change into the project directory before installing dependencies. section 3.4.2
  • Run npm install in a deployment hook so each pushed commit refreshes the application dependencies. section 3.4.2
  • Run it in a Dockerfile after copying package.json and package-lock.json, helping keep container builds consistent. section 5.4.2

Installing an Express.js application's dependencies

cd /opt/projects/roadtok8s/js npm install -g npm@latest npm install npm list The same project can install its dependencies automatically after a repository push by running npm install from the Git post-receive hook. section 3.4.2

Listing 5.13 Node.js Dockerfile
# Using the official Node.js image for the LTS version
FROM node:18.17.0

# Set our app's working directory
WORKDIR /app

# copy the primary source code
COPY ./src /app/src/

# copy the package.json and package-lock.json to
# ensure we use the same dependencies
COPY package.json /app/
COPY package-lock.json /app/

# copy the entrypoint.sh for running the app
COPY conf/entrypoint.sh /app/

# install dependencies
RUN npm install

# make the entrypoint.sh executable
RUN chmod +x entrypoint.sh

# run our app
CMD ["./entrypoint.sh"]

Inspect the complete Dockerfile showing where npm install fits after copying the project manifests and before launching the application. section 5.4.2

How Road to Kubernetes covers it

How deep it goes
Shows command placement in deployment hooks and Dockerfiles, but does not explain npm's dependency-resolution internals.
Examples
Uses an Express.js project command sequence, a Git post-receive hook, and a Node.js Dockerfile.
What it assumes
Assumes a Node.js project with package manifests and a deployment or container workflow; does not require Python virtual-environment setup.
What you can do after
Operate npm to install dependencies manually, after repository pushes, or while building a Node.js container image.
How it connects
Connects npm install with Node.js, Express.js, package.json, package-lock.json, Git hooks, Docker, and Dockerfiles.

Also explained in

Compare how 2 books explain npm install →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Road to Kubernetes. The section links point to the parts of the book it draws on.