LogoMkSaaS Docs

Environment Setup

Configure environment variables for your MkSaaS application

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:

cp env.example .env

Environment Variables

Core Configuration

VariableDescription
NEXT_PUBLIC_BASE_URLThe public URL of your site, e.g.
http://localhost:3000 for development,
https://yourdomain.com for production
PORTThe 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.

VariableDescription
DATABASE_URLDatabase connection URL

Authentication

Learn how to set up authentication in the Authentication Setup guide.

VariableDescription
BETTER_AUTH_SECRETA random string used to hash tokens and sign cookies
GOOGLE_CLIENT_IDGoogle OAuth client ID (optional)
GOOGLE_CLIENT_SECRETGoogle OAuth client secret (optional)
GITHUB_CLIENT_IDGitHub OAuth client ID (optional)
GITHUB_CLIENT_SECRETGitHub OAuth client secret (optional)

Email

Learn how to set up email in the Email Setup guide.

VariableDescription
RESEND_API_KEYAPI key for Resend email service

Newsletter

Learn how to set up newsletter in the Newsletter Setup guide.

VariableDescription
RESEND_API_KEYAPI key for Resend email service
RESEND_AUDIENCE_IDAudience ID for Resend broadcast service

Storage

Learn how to set up storage in the Storage Setup guide.

VariableDescription
STORAGE_REGIONRegion for the storage bucket
STORAGE_BUCKET_NAMEName of the storage bucket
STORAGE_ACCESS_KEY_IDAccess key ID for the storage bucket
STORAGE_SECRET_ACCESS_KEYSecret access key for the storage bucket
STORAGE_ENDPOINTEndpoint for the storage bucket
STORAGE_FORCE_PATH_STYLEForce path style for the storage bucket
STORAGE_PUBLIC_URLPublic URL for the storage bucket

Payment

Learn how to set up payments in the Payment Setup guide.

VariableDescription
STRIPE_SECRET_KEYStripe secret key
STRIPE_WEBHOOK_SECRETStripe webhook signing secret
NEXT_PUBLIC_STRIPE_PRICE_PRO_MONTHLYStripe price ID for your pro monthly subscription
NEXT_PUBLIC_STRIPE_PRICE_PRO_YEARLYStripe price ID for your pro yearly subscription
NEXT_PUBLIC_STRIPE_PRICE_LIFETIMEStripe price ID for your lifetime subscription

Analytics

Learn how to set up analytics in the Analytics Setup guide.

VariableDescription
GOOGLE_ANALYTICS_IDGoogle Analytics ID for analytics features
UMAMI_WEBSITE_IDUmami Analytics website ID for analytics features
UMAMI_SCRIPTUmami Analytics script URL for analytics features
OPENPANEL_CLIENT_IDOpenPanel Analytics client ID for analytics features
PLAUSIBLE_DOMAINPlausible Analytics domain for analytics features
PLAUSIBLE_SCRIPTPlausible Analytics script URL for analytics features
Seline_TOKENSeline Analytics token for analytics features
DATAFAST_ANALYTICS_IDDataFast Analytics ID for analytics features
DATAFAST_ANALYTICS_DOMAINDataFast Analytics domain for analytics features

AI Features

Learn how to set up AI features in the AI Setup guide.

VariableDescription
OPENAI_API_KEYOpenAI API key for AI features
GOOGLE_API_KEYGoogle API key for AI features
DEEPSEEK_API_KEYDeepSeek 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.

VariableDescription
DISABLE_IMAGE_OPTIMIZATIONDisable image optimization, if you deploy your website to Vercel, image optimization is enabled by default, and may cost you more money
NEXT_PUBLIC_DEMO_WEBSITERun 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_URLDiscord webhook URL for receiving notifications of successful payments
NEXT_PUBLIC_DISCORD_WIDGET_SERVER_IDDiscord server ID for the widget in the bottom right corner
NEXT_PUBLIC_DISCORD_WIDGET_CHANNEL_IDDiscord 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 and NEXT_PUBLIC_DISCORD_WIDGET_CHANNEL_ID environment variables.

Verifying Environment Variables

To verify that your environment variables are correctly set up, run:

pnpm run dev

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:

Table of Contents