Welcome to NOW.TS directory.
Please follow the NOW.TS Course to setup the project.
Before running the application, you'll need to configure several environment variables. Copy the .env-template file to .env and fill in the required values:
cp .env-template .envYou can install Postgres (MacOS) or Postgres (Windows) to have a local database.
Launch the application, then configure your database URL:
DATABASE_URL="postgresql://NAME:@localhost:5432/PROJECT_NAME"To find your NAME:
# MacOS/Linux
whoami
# Windows
echo %username%For PROJECT_NAME, choose any name you want - we recommend using the same name as your application.
Redis is required for caching and provides ~90% performance improvement.
macOS (using Homebrew):
# Install Redis
brew install redis
# Start Redis server
brew services start redis
# Or run manually
redis-serverSee the official macOS installation guide for more details.
Windows:
Download and install Redis from the official Windows guide.
Linux:
# Ubuntu/Debian
sudo apt-get install redis-server
# Start Redis
sudo systemctl start redis-serverAfter installation, add to your .env:
REDIS_URL=redis://localhost:6379# Start Redis with Docker
docker run -d -p 6379:6379 redis:alpine
# Add to .env
REDIS_URL=redis://localhost:6379For production deployments, we recommend using a managed Redis service:
Upstash (Serverless Redis):
- Free tier: 10,000 commands/day
- Serverless with pay-per-use pricing
- Sign up at console.upstash.com
- Copy your Redis URL and add to
.env
Redis Cloud (Official Redis):
- Free tier: 30MB RAM
- Managed by Redis Labs
- Sign up at redis.com/try-free
- Get your connection URL from the dashboard
Railway:
- $5/month for 512MB RAM
- Simple setup and deployment
- Go to railway.app and deploy Redis
For detailed setup instructions for each provider, see the Redis Setup Guide.
For Better-Auth, we recommend starting with the GitHub provider. You can add more providers later.
By default, the template also includes Magic Link (requires Resend setup) and email/password authentication.
You'll need a GITHUB_CLIENT_ID and GITHUB_CLIENT_SECRET from GitHub Developer Settings.
Configure these settings:
Authorization callback URL:http://localhost:3000/api/auth/callback/githubHomepage URL:http://localhost:3000
Then add to your .env:
GITHUB_CLIENT_ID="YOUR_GITHUB_ID"
GITHUB_CLIENT_SECRET="YOUR_GITHUB_SECRET"Generate a BETTER_AUTH_SECRET:
node -e "console.log(require('crypto').randomBytes(32).toString('base64'))"Copy the result and add it to your .env:
BETTER_AUTH_SECRET="YOUR_SECRET"Create a Resend account and create an API key. You'll also need to configure a domain - either your application's domain or any domain you own.
Add the API key to your .env:
RESEND_API_KEY="YOUR_API_KEY"
EMAIL_FROM="contact@yourdomain.com"
NEXT_PUBLIC_EMAIL_CONTACT="your@email.com"An audience allows you to send marketing emails to your users (e.g., product launch announcements, promotions).
The application works without an audience, but it's useful for sending bulk emails to your user base.
To create an audience:
- Go to Resend Audiences
- Create a new audience
- Copy the audience ID and add it to your
.env:
RESEND_AUDIENCE_ID="YOUR_AUDIENCE_ID"If you don't have a Stripe account yet, create one.
Follow this documentation to get your test API keys.
Add them to your .env:
STRIPE_SECRET_KEY="sk_test_..."
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="pk_test_..."For webhooks, first login to Stripe CLI:
stripe loginThen run the webhook listener:
pnpm run stripe-webhooksCopy the webhook secret from the output and add it to your .env:
STRIPE_WEBHOOK_SECRET="whsec_..."Note: Each time you want to use webhooks during development, you'll need to run
pnpm stripe-webhooksto forward Stripe events to your local application. The webhook secret remains the same.
Uploadthing is a SaaS for managing images in your application.
Go to your Uploadthing dashboard and get a token:
UPLOADTHING_TOKEN='YOUR_TOKEN'Once all environment variables are configured, install dependencies and start the development server:
pnpm install
pnpm devTest that everything works by:
- Logging in with GitHub
- Creating an account
- Verifying emails are sent
- Testing other features
NOW.TS uses Redis caching to provide exceptional performance, reducing database queries by ~90% and middleware execution time from ~200-500ms to <20ms.
Without caching:
- Every page navigation hits the database 2-3 times
- Middleware validates sessions and organization membership repeatedly
- External Stripe API calls on every page load
- Slow response times and high database load
With Redis caching:
- 80-95% of requests served from cache
- Session validation cached for 5 minutes
- Organization lookups cached for 5 minutes
- Stripe subscription data cached for 1 hour
- ~90% performance improvement
For local development:
# Start Redis with Docker
docker run -d -p 6379:6379 redis:alpine
# Add to .env.local
REDIS_URL=redis://localhost:6379For production (recommended providers):
- Railway: $5/month - Setup Guide
- Redis Cloud: Free tier available - Setup Guide
- Upstash: Pay-per-use - Setup Guide
See docs/redis-setup.md for complete setup instructions.
- Session validation (5 min TTL) - Better Auth cookie caching + Redis
- Organization membership (5 min TTL) - Middleware checks
- User's organizations (10 min TTL) - Organization list
- Stripe subscriptions (1 hour TTL) - Billing data
Caches are automatically invalidated when:
- User updates their profile
- Organization settings change
- Membership changes (add/remove members)
- Subscription updates via Stripe webhooks
Real-world metrics:
- Middleware execution: ~200-500ms → <20ms (~90% faster)
- Database queries per request: 2-3 → ~0.2 (90% reduction)
- Cache hit rate: 80-95% after warmup
- Page load improvement: 30-50% faster overall
Feel free to create a pull request with any changes you think valuable