# Use Node.js LTS as the base image FROM node:20-slim # Create app directory and set ownership WORKDIR /app # Copy package.json and package-lock.json COPY package*.json ./ # Install production dependencies only RUN npm install --omit=dev # Copy application files COPY . . # Create a non-root user and switch to it RUN groupadd -r nodejs && useradd -r -g nodejs nodejs \ && chown -R nodejs:nodejs /app USER nodejs # Expose the port the app runs on EXPOSE 3000 # Set NODE_ENV to production ENV NODE_ENV=production # Command to run the application CMD ["node", "server.js"]