
How to set up
How to build your AI SaaS with MkSaaS template
MkSaaS requires several environment variables to function properly, and 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:
Environment Variables
Core Configuration
Variable | Description |
---|---|
NEXT_PUBLIC_BASE_URL | The public URL of your site, e.g. http://localhost:3000 for development, https://yourdomain.com for production |
PORT | The port number to run the server on in development mode, e.g. 3005 , default is 3000 . No need to set in production mode. |
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 |
RESEND_AUDIENCE_ID | Audience ID for Resend broadcast 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_FORCE_PATH_STYLE | Force path style 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.
Variable | Description |
---|---|
STRIPE_SECRET_KEY | Stripe secret key |
STRIPE_WEBHOOK_SECRET | Stripe webhook signing secret |
NEXT_PUBLIC_STRIPE_PRICE_PRO_MONTHLY | Stripe price ID for your pro monthly subscription |
NEXT_PUBLIC_STRIPE_PRICE_PRO_YEARLY | Stripe price ID for your pro yearly subscription |
NEXT_PUBLIC_STRIPE_PRICE_LIFETIME | Stripe price ID for your lifetime subscription |
Analytics
Learn how to set up analytics in the Analytics Setup guide.
Variable | Description |
---|---|
GOOGLE_ANALYTICS_ID | Google Analytics ID for analytics features |
UMAMI_WEBSITE_ID | Umami Analytics website ID for analytics features |
UMAMI_SCRIPT | Umami Analytics script URL for analytics features |
OPENPANEL_CLIENT_ID | OpenPanel Analytics client ID for analytics features |
PLAUSIBLE_DOMAIN | Plausible Analytics domain for analytics features |
PLAUSIBLE_SCRIPT | Plausible Analytics script URL for analytics features |
Seline_TOKEN | Seline Analytics token for analytics features |
DATAFAST_ANALYTICS_ID | DataFast Analytics ID for analytics features |
DATAFAST_ANALYTICS_DOMAIN | DataFast Analytics domain for analytics features |
AI Features
Learn how to set up AI features in the AI Setup guide.
Variable | Description |
---|---|
OPENAI_API_KEY | OpenAI API key for AI features |
GOOGLE_API_KEY | Google API key for AI features |
DEEPSEEK_API_KEY | DeepSeek API key for AI features |
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 |
DISCORD_WEBHOOK_URL | Discord webhook URL for receiving notifications of successful payments |
NEXT_PUBLIC_DISCORD_WIDGET_SERVER_ID | Discord server ID for the widget in the bottom right corner |
NEXT_PUBLIC_DISCORD_WIDGET_CHANNEL_ID | Discord channel ID for the widget in the bottom right corner |
- If you want to use the Discord widget, you need to invite the bot to your Discord server first, and you can get started by following this tutorial.
- After setting up the Discord widget bot, you need to set the
NEXT_PUBLIC_DISCORD_WIDGET_SERVER_ID
andNEXT_PUBLIC_DISCORD_WIDGET_CHANNEL_ID
environment variables.
Verifying Environment Variables
To verify that your environment variables are correctly set up, run:
If everything is configured correctly, your application should start and run normally without any environment-related errors.
Next Steps
Now that your environment is set up, explore these related topics:
Author

Categories
More Posts
Newsletter
Join the community
Subscribe to our newsletter for the latest news and updates