FROM node:18-alpine

WORKDIR /app

# Copy package.json and package-lock.json first (this leverages Docker cache for better efficiency)
COPY package.json .
COPY package-lock.json .

# Install dependencies
RUN npm install

# Copy the rest of the application code
COPY . .

# Copy .env file if necessary for environment variables
COPY .env .env

# Expose the application port
EXPOSE 3000

# Command to run the application
CMD ["npm", "start"]

# Optionally, add a health check
# HEALTHCHECK CMD curl --fail http://localhost:3000/ || exit 1