
How to set up
How to build your AI SaaS with MkSaaS template
MkSaaS requires several environment variables to work correctly. This guide explains how to set them up.
Create a .env file in the root directory of your project, and never commit it to version control.
You can copy the example file as a starting point:
cp env.example .envEnvironment Variables
Core Configuration
| Variable | Description |
|---|---|
| NEXT_PUBLIC_BASE_URL | The public URL of your site, e.g. http://localhost:3000 for development, https://YOUR-DOMAIN.com for production |
Database
Learn how to set up a database in the Database Setup guide.
| Variable | Description |
|---|---|
| DATABASE_URL | Database connection URL |
Authentication
Learn how to set up authentication in the Authentication Setup guide.
| Variable | Description |
|---|---|
| BETTER_AUTH_SECRET | A random string used to hash tokens and sign cookies |
| GOOGLE_CLIENT_ID | Google OAuth client ID (optional) |
| GOOGLE_CLIENT_SECRET | Google OAuth client secret (optional) |
| GITHUB_CLIENT_ID | GitHub OAuth client ID (optional) |
| GITHUB_CLIENT_SECRET | GitHub OAuth client secret (optional) |
Learn how to set up email in the Email Setup guide.
| Variable | Description |
|---|---|
| RESEND_API_KEY | API key for Resend email service |
Newsletter
Learn how to set up newsletter in the Newsletter Setup guide.
| Variable | Description |
|---|---|
| RESEND_API_KEY | API key for Resend email service |
Storage
Learn how to set up storage in the Storage Setup guide.
| Variable | Description |
|---|---|
| STORAGE_REGION | Region for the storage bucket |
| STORAGE_BUCKET_NAME | Name of the storage bucket |
| STORAGE_ACCESS_KEY_ID | Access key ID for the storage bucket |
| STORAGE_SECRET_ACCESS_KEY | Secret access key for the storage bucket |
| STORAGE_ENDPOINT | Endpoint for the storage bucket |
| STORAGE_PUBLIC_URL | Public URL for the storage bucket |
Payment
Learn how to set up payments in the Payment Setup guide.
Select the active provider with NEXT_PUBLIC_PAYMENT_PROVIDER: stripe,
creem, or waffo (default: stripe). Configure only the credentials and
price/product IDs for the provider you use.
| Variable | Description |
|---|---|
| NEXT_PUBLIC_PAYMENT_PROVIDER | Active provider: stripe, creem, or waffo (default: stripe) |
| STRIPE_SECRET_KEY | Stripe secret key |
| STRIPE_WEBHOOK_SECRET | Stripe webhook signing secret |
| NEXT_PUBLIC_STRIPE_PRICE_PRO_MONTHLY | Stripe price ID for pro monthly subscription |
| NEXT_PUBLIC_STRIPE_PRICE_PRO_YEARLY | Stripe price ID for pro yearly subscription |
| NEXT_PUBLIC_STRIPE_PRICE_LIFETIME | Stripe price ID for lifetime subscription |
| NEXT_PUBLIC_STRIPE_PRICE_CREDITS_BASIC | Stripe price ID for basic credit package (optional) |
| NEXT_PUBLIC_STRIPE_PRICE_CREDITS_STANDARD | Stripe price ID for standard credit package (optional) |
| NEXT_PUBLIC_STRIPE_PRICE_CREDITS_PREMIUM | Stripe price ID for premium credit package (optional) |
| NEXT_PUBLIC_STRIPE_PRICE_CREDITS_ENTERPRISE | Stripe price ID for enterprise credit package (optional) |
| CREEM_DEBUG | Set to true to use Creem's test API (optional) |
| CREEM_API_KEY | Creem API key |
| CREEM_WEBHOOK_SECRET | Creem webhook signing secret |
| NEXT_PUBLIC_CREEM_PRODUCT_PRO_MONTHLY | Creem product ID for pro monthly subscription |
| NEXT_PUBLIC_CREEM_PRODUCT_PRO_YEARLY | Creem product ID for pro yearly subscription |
| NEXT_PUBLIC_CREEM_PRODUCT_LIFETIME | Creem product ID for lifetime one-time payment |
| NEXT_PUBLIC_CREEM_PRODUCT_CREDITS_BASIC | Creem product ID for basic credit package (optional) |
| NEXT_PUBLIC_CREEM_PRODUCT_CREDITS_STANDARD | Creem product ID for standard credit package (optional) |
| NEXT_PUBLIC_CREEM_PRODUCT_CREDITS_PREMIUM | Creem product ID for premium credit package (optional) |
| NEXT_PUBLIC_CREEM_PRODUCT_CREDITS_ENTERPRISE | Creem product ID for enterprise credit package (optional) |
| WAFFO_DEBUG | Set to true to accept sandbox webhooks in a production build (optional, smoke testing only) |
| WAFFO_MERCHANT_ID | Waffo Merchant ID from Dashboard > API & Development |
| WAFFO_PRIVATE_KEY | Waffo private key, server-side only; preserve PEM line breaks with escaped \n |
| NEXT_PUBLIC_WAFFO_PRODUCT_PRO_MONTHLY | Waffo product ID for pro monthly subscription |
| NEXT_PUBLIC_WAFFO_PRODUCT_PRO_YEARLY | Waffo product ID for pro yearly subscription |
| NEXT_PUBLIC_WAFFO_PRODUCT_LIFETIME | Waffo product ID for lifetime one-time payment |
| NEXT_PUBLIC_WAFFO_PRODUCT_CREDITS_BASIC | Waffo product ID for basic credit package (optional) |
| NEXT_PUBLIC_WAFFO_PRODUCT_CREDITS_STANDARD | Waffo product ID for standard credit package (optional) |
| NEXT_PUBLIC_WAFFO_PRODUCT_CREDITS_PREMIUM | Waffo product ID for premium credit package (optional) |
| NEXT_PUBLIC_WAFFO_PRODUCT_CREDITS_ENTERPRISE | Waffo product ID for enterprise credit package (optional) |
AI Features
Learn how to set up AI features in the AI Setup guide.
| Variable | Description |
|---|---|
| OPENAI_API_KEY | API key for OpenAI |
| FAL_API_KEY | API key for FAL |
| FIREWORKS_API_KEY | API key for Fireworks |
| REPLICATE_API_TOKEN | API key for Replicate |
| GOOGLE_GENERATIVE_AI_API_KEY | API key for Google Generative AI |
| DEEPSEEK_API_KEY | API key for DeepSeek |
| OPENROUTER_API_KEY | API key for OpenRouter |
Cron Jobs
Learn how to set up cron jobs in the Cron Jobs Setup guide.
| Variable | Description |
|---|---|
| CRON_JOBS_USERNAME | Username for basic authentication to trigger cron jobs |
| CRON_JOBS_PASSWORD | Password for basic authentication to trigger cron jobs |
Analytics
Learn how to set up analytics in the Analytics Setup guide.
| Variable | Description |
|---|---|
| GOOGLE_ANALYTICS_ID | Google Analytics ID |
| UMAMI_WEBSITE_ID | Umami Analytics website ID |
| UMAMI_SCRIPT | Umami Analytics script URL |
| OPENPANEL_CLIENT_ID | OpenPanel Analytics client ID |
| PLAUSIBLE_DOMAIN | Plausible Analytics domain |
| PLAUSIBLE_SCRIPT | Plausible Analytics script URL |
| Seline_TOKEN | Seline Analytics token |
| DATAFAST_ANALYTICS_ID | DataFast Analytics ID |
| DATAFAST_ANALYTICS_DOMAIN | DataFast Analytics domain |
Notification
Learn how to set up notification in the Notification Setup guide.
| Variable | Description |
|---|---|
| DISCORD_WEBHOOK_URL | Discord webhook URL for receiving notifications of successful payments |
| FEISHU_WEBHOOK_URL | Feishu webhook URL for receiving notifications of successful payments |
Captcha
Learn how to set up captcha in the Captcha Setup guide.
| Variable | Description |
|---|---|
| NEXT_PUBLIC_TURNSTILE_SITE_KEY | Turnstile site key |
| TURNSTILE_SECRET_KEY | Turnstile secret key |
Chatbox
Learn how to set up chatbox in the Chatbox Setup guide.
| Variable | Description |
|---|---|
| NEXT_PUBLIC_CRISP_WEBSITE_ID | Crisp website ID for chat features |
Affiliates
Learn how to set up affiliates in the Affiliates Setup guide.
| Variable | Description |
|---|---|
| NEXT_PUBLIC_AFFILIATE_AFFONSO_ID | Affonso affiliate ID |
| NEXT_PUBLIC_AFFILIATE_PROMOTEKIT_ID | Promotekit affiliate ID |
Other Configurations
Some other configurations are also available in the .env file, you may need to set them up depending on your needs.
| Variable | Description |
|---|---|
| DISABLE_IMAGE_OPTIMIZATION | Disable image optimization, if you deploy your website to Vercel, image optimization is enabled by default, and may cost you more money |
| NEXT_PUBLIC_DEMO_WEBSITE | Run this website as demo website, I use this for MkSaaS demo website. In most cases, you should not set this or leave it to false |
Verifying Environment Variables
To verify that your environment variables are correctly set up, run:
pnpm run devIf everything is configured correctly, your application should start without any environment-related errors.
Next Steps
Now that your environment is set up, explore these related topics:
Más publicaciones

2025年的年终总结
2025年的年终总结,回顾过去独立开发之路,展望未来产品出海规划

MkSaaS AI Module
Deep dive into MkSaaS template's AI module, including AI chatbot, AI text generator, AI image generator, and other core features to help you quickly build powerful AI SaaS applications

Video Tutorials
Video tutorials for MkSaaS template
Boletín
Únete a la comunidad
Suscríbete a nuestro boletín para recibir las últimas noticias y actualizaciones.