Docker Puppeeteer Node Railway

om0509

Om Bharti

Posted on April 16, 2024

Docker Puppeeteer Node Railway

Want to use puppeteer in node node and then deploy it on railway.app or any related hosting platform, here is my working docker file and puppeteer config. You can use it

-------------------------------------------------------------------------------------------DOCKER CONFIG FILE--------------------------------------------------------------------------------------------------------------------------------------------------------------

# Use the latest Node.js LTS (Long Term Support) version as the base image
FROM node:21.7.3-slim

RUN apt-get update && apt-get install gnupg wget -y && \
  wget --quiet --output-document=- https://dl-ssl.google.com/linux/linux_signing_key.pub | gpg --dearmor > /etc/apt/trusted.gpg.d/google-archive.gpg && \
  sh -c 'echo "deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list' && \
  apt-get update && \
  apt-get install google-chrome-stable -y --no-install-recommends && \
  rm -rf /var/lib/apt/lists/*

# Set the working directory to /app
WORKDIR /app

# Copy the package.json and pnpm-lock.yaml files
COPY package.json pnpm-lock.yaml ./

# Install dependencies using pnpm
RUN npm install -g pnpm && pnpm install

# Copy the rest of the application code
COPY . .

# Set the DATABASE_URL environment variable
ENV DATABASE_URL="postgres://postgres.<passwoedtodb>.supabase.com:5432/postgres"

# Set the NEXT_PUBLIC_API_URL environment variable
ENV NEXT_PUBLIC_API_URL="https://example.com"

# Build the TypeScript code and run Prisma migrations
RUN pnpm run build

# Expose the port that your Express.js app is running on
EXPOSE 3000

# Start the application
CMD ["pnpm", "start"]
Enter fullscreen mode Exit fullscreen mode

--------------------------------------------------------------------------------------------import puppeteer from "puppeteer";

const browser = await puppeteer.launch({
// headless: false,
executablePath: '/usr/bin/google-chrome',
args: ["--no-sandbox", "--disable-setuid-sandbox"],
});
const page = await browser.newPage();

💖 💪 🙅 🚩
om0509
Om Bharti

Posted on April 16, 2024

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

Docker Puppeeteer Node Railway
webdev Docker Puppeeteer Node Railway

April 16, 2024