For example, we can copy & build the package.json first. Since dependencies usually don’t really change. If we include the dependencies installation with the main application. We need to re-install the dependencies whenever there is a change to the application
FROM node:18-alpine3.15WORKDIR /xy241# Install dependencies first to take advantage of Docker's cachingCOPY package.json .RUN npm install COPY . .EXPOSE 3000CMD ["npm", "npm.js"]