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

