AI News App is a Next.js project that fetches news articles, stores them in PostgreSQL with Prisma, shows them in a feed, supports Google login, Redis caching, and AI article summaries.
- Install dependencies:
npm install- Create a
.envfile in the project root and add these values:
DATABASE_URL=
NEXTAUTH_URL=
NEXTAUTH_SECRET=
GOOGLE_ID=
GOOGLE_SECRET=
GOOGLE_GEMINI_API=
NEWS_API=
UPSTASH_REDIS_REST_URL=
UPSTASH_REDIS_REST_TOKEN=- Run the app locally:
npm run dev- Build for production:
npm run buildDATABASE_URL: PostgreSQL connection string.NEXTAUTH_URL: Base URL of your app, such ashttp://localhost:3000.NEXTAUTH_SECRET: A secret string used by NextAuth.GOOGLE_IDandGOOGLE_SECRET: OAuth client ID and secret from Google Cloud.GOOGLE_GEMINI_API: API key from Google AI Studio.NEWS_API: API key from World News API.UPSTASH_REDIS_REST_URL: The REST URL provided by Upstash Redis.UPSTASH_REDIS_REST_TOKEN: The REST token provided by Upstash Redis.
Use this command to create a strong secret for NEXTAUTH_SECRET:
openssl rand -base64 32Copy the output into your .env file.
- The app uses World News API for fetching news.
- Google login needs an OAuth client created in Google Cloud Console.
- Gemini summaries need a key from Google AI Studio.
- AI generated summaries are securely cached in Redis to drastically reduce API costs and improve response times (from ~8.2s down to ~72ms).
This app uses a scheduled background job to fetch news 6 times a day (every 4 hours).
- Vercel Deployments: Set
CRON_SECRETin your project environment variables so scheduled calls can authenticate to/api/jobs. - Azure / VPS / Docker: You must run the cron script alongside your web server. In your environment, start the background worker process using:
npm run cron. Make sure bothNEXTAUTH_URL(e.g.,NEXTAUTH_URL=https://your-production-domain.com) andCRON_SECRETare set so the cron script can call the protected endpoint.
A simple health check endpoint is available for CI/CD pipelines, Docker deployments, or uptime monitors.
To verify the app is running, run:
curl http://localhost:3000/api/healthExpected Response:
{
"status": "ok",
"timestamp": "2026-08-09T12:00:00.000Z"
}