# # Use the official Node.js runtime as the base image # FROM node:18-alpine # # Set the working directory inside the container # WORKDIR /app # # Copy package.json and package-lock.json (if available) # COPY package*.json ./ # # Install dependencies # RUN npm install --production # # Copy the rest of the application code # COPY . . # # Create a non-root user to run the app # RUN addgroup -g 1001 -S nodejs # RUN adduser -S nodejs -u 1001 # # Change ownership of the app directory to the nodejs user # RUN chown -R nodejs:nodejs /app # USER nodejs # # Expose the port that the app runs on # EXPOSE 5000 # # Define environment variables # ENV NODE_ENV=production # ENV PORT=5000 # # Health check # HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ # CMD node healthcheck.js # # Start the application # CMD ["npm", "start"] # Use the official Node.js runtime as the base image FROM node:18-alpine # Set working directory WORKDIR /app # Copy dependency files first (for layer caching) COPY package*.json ./ # Install only production dependencies RUN npm ci --only=production # Copy rest of the application code COPY . . # Create a non-root user for security RUN addgroup -g 1001 -S nodejs && adduser -S nodejs -u 1001 USER nodejs # Hugging Face Spaces expects your app to run on port 7860 ENV NODE_ENV=production ENV PORT=7860 EXPOSE 7860 # (Optional) Disable healthcheck if not implemented properly # HF Spaces automatically checks if the container is responding on exposed port # Comment this back in only if you have a working healthcheck.js file HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \ CMD node healthcheck.js # Start the Node.js application CMD ["npm", "start"]