Deploy Nuxt
This guide will help you deploy a Nuxt application to Deployxa.
Overview
Nuxt is a Vue.js framework for building full-stack web applications with server-side rendering (SSR) and static site generation (SSG). Deployxa provides optimized deployments for Nuxt with automatic configuration.
Features:
- Automatic framework detection
- Server-side rendering (SSR)
- Static site generation (SSG)
- API routes support
- Automatic HTTPS
- Global CDN
Prerequisites
- A Nuxt application (version 3 recommended)
- A GitHub repository with your code
- A Deployxa account
Quick Start
1. Create Your Nuxt App
If you don't have a Nuxt app yet:
npx nuxi@latest init my-nuxt-app
cd my-nuxt-app
npm install
2. Push to GitHub
git init
git add .
git commit -m "Initial commit"
git remote add origin https://github.com/yourusername/my-nuxt-app.git
git push -u origin main
3. Deploy to Deployxa
- Go to Deployxa Dashboard
- Click "New Project"
- Select your GitHub repository
- Deployxa will automatically detect Nuxt
- Click "Deploy"
Your app will be live in under 60 seconds!
Configuration
Detected Settings
Deployxa automatically detects these settings:
| Setting | Value |
|---|---|
| Framework | Nuxt |
| Build Command | npm run build |
| Output Directory | .output |
| Start Command | node .output/server/index.mjs |
| Port | 3000 |
Custom Configuration
If you need to customize settings:
- Go to Project → Settings → Build
- Modify settings as needed
- Save changes
Example Custom Settings:
{
"buildCommand": "npm run build",
"outputDirectory": ".output",
"startCommand": "node .output/server/index.mjs"
}
Environment Variables
Adding Environment Variables
- Go to Project → Environment
- Click "Add Variable"
- Enter key and value
- Click "Save"
Common Nuxt Environment Variables:
NUXT_PUBLIC_API_URL=https://api.example.com
NUXT_API_SECRET=your-api-secret
DATABASE_URL=postgresql://user:pass@host:5432/db
Note: Variables prefixed with NUXT_PUBLIC_ are exposed to the client.
Using Environment Variables
In your Nuxt app:
// Server-side only
const apiUrl = useRuntimeConfig().apiUrl;
// Available on both server and client
const publicApiUrl = useRuntimeConfig().public.apiUrl;
Configure in nuxt.config.ts:
export default defineNuxtConfig({
runtimeConfig: {
apiSecret: '',
public: {
apiUrl: ''
}
}
})
Build Process
What Happens During Build
- Install Dependencies:
npm installornpm ci - Run Build:
npm run build - Generate Server Bundle: Build server-side code
- Generate Client Bundle: Build client-side code
- Create Output: Generate
.outputdirectory - Deploy: Deploy to edge network
Build Output
Nuxt generates:
.output/- Build output directory.output/server/- Server-side code.output/public/- Static assets.output/server/index.mjs- Server entry point
Rendering Modes
Server-Side Rendering (SSR)
Default mode for dynamic content:
// nuxt.config.ts
export default defineNuxtConfig({
ssr: true
})
Benefits:
- SEO friendly
- Fast initial load
- Dynamic content
Static Site Generation (SSG)
For mostly static content:
// nuxt.config.ts
export default defineNuxtConfig({
ssr: false
})
Benefits:
- Fast load times
- CDN caching
- Low resource usage
Hybrid Rendering
Mix SSR and SSG:
// nuxt.config.ts
export default defineNuxtConfig({
routeRules: {
'/': { prerender: true },
'/blog/**': { isr: 3600 },
'/admin/**': { ssr: false }
}
})
API Routes
Creating API Routes
Create files in server/api/:
// server/api/hello.ts
export default defineEventHandler((event) => {
return {
message: 'Hello from Nuxt API!'
}
})
Access: https://your-app.deployxa.app/api/hello
With Database
// server/api/users.get.ts
import { prisma } from '~/lib/prisma'
export default defineEventHandler(async () => {
const users = await prisma.user.findMany()
return users
})
POST Requests
// server/api/users.post.ts
export default defineEventHandler(async (event) => {
const body = await readBody(event)
// Process body
return { success: true }
})
Custom Domains
Adding a Custom Domain
- Go to Project → Domains
- Click "Add Domain"
- Enter your domain (e.g.,
example.com) - Configure DNS records
- Wait for verification
DNS Configuration
For Apex Domain (example.com):
Type: A
Name: @
Value: 76.76.21.21
For Subdomain (www.example.com):
Type: CNAME
Name: www
Value: cname.deployxa.com
Performance Optimization
Enable Nitro Compression
Nuxt uses Nitro which automatically enables compression.
Enable Caching
Configure caching in nuxt.config.ts:
export default defineNuxtConfig({
routeRules: {
'/api/**': { cors: true },
'/blog/**': { isr: 3600 }
}
})
Optimize Images
Use Nuxt Image:
npm install @nuxt/image
// nuxt.config.ts
export default defineNuxtConfig({
modules: ['@nuxt/image']
})
<NuxtImg src="/image.jpg" width="500" height="500" />
Code Splitting
Nuxt automatically code-splits by default.
Monitoring
Viewing Logs
- Go to Project → Logs
- Select log type:
- Build Logs: Deployment process
- Runtime Logs: Application output
- Error Logs: Application errors
Monitoring Metrics
- Go to Project → Analytics
- View metrics:
- Request count
- Response times
- Error rates
- Bandwidth usage
- CPU/RAM usage
Health Checks
Deployxa automatically monitors your application:
- HTTP health checks every 30 seconds
- Automatic restart on failure
- Alerts on consecutive failures
Troubleshooting
Build Failed: Module Not Found
Problem: Module not found: Can't resolve 'package-name'
Solution:
- Check
package.jsonhas the dependency - Run
npm install package-namelocally - Commit and push changes
- Redeploy
Runtime Error: Port Already in Use
Problem: Error: listen EADDRINUSE: address already in use :::3000
Solution:
- Deployxa automatically handles port configuration
- Ensure your code uses
process.env.PORTor defaults to 3000
Pages Not Loading
Problem: Pages return 404 or blank
Solution:
- Check build logs for errors
- Verify file structure
- Ensure
nuxt.config.tsis correct - Check runtime logs for errors
API Routes Not Working
Problem: API routes return 404
Solution:
- Check files are in
server/api/directory - Verify file naming convention
- Check runtime logs for errors
- Ensure proper HTTP method handling
Slow Build Times
Problem: Build takes too long
Solution:
- Use
npm ciinstead ofnpm install - Enable dependency caching
- Reduce build steps
- Consider upgrading plan
Best Practices
Project Structure
my-nuxt-app/
├── pages/
│ ├── index.vue
│ └── about.vue
├── components/
│ └── MyComponent.vue
├── composables/
│ └── useMyComposable.ts
├── server/
│ └── api/
│ └── hello.ts
├── public/
│ └── favicon.ico
├── nuxt.config.ts
├── package.json
└── README.md
Environment Variables
- Use
.envfor local development - Never commit
.envfiles - Use
NUXT_PUBLIC_prefix for client-side variables - Rotate secrets regularly
Performance
- Use ISR (Incremental Static Regeneration)
- Enable image optimization
- Use code splitting
- Minimize bundle size
- Enable compression
Security
- Never expose secrets in client code
- Use HTTPS only
- Validate all inputs
- Use CSRF protection
- Keep dependencies updated
Advanced Configuration
Custom Nuxt Config
// nuxt.config.ts
export default defineNuxtConfig({
ssr: true,
app: {
head: {
title: 'My Nuxt App',
meta: [
{ name: 'description', content: 'My Nuxt application' }
]
}
},
modules: [
'@nuxtjs/tailwindcss',
'@pinia/nuxt'
],
runtimeConfig: {
apiSecret: '',
public: {
apiUrl: ''
}
},
routeRules: {
'/': { prerender: true },
'/blog/**': { isr: 3600 }
},
nitro: {
preset: 'node-server'
}
})
Custom Server
For advanced use cases, you can customize the Nitro server:
// server/plugins/custom.ts
export default defineNitroPlugin((nitroApp) => {
nitroApp.hooks.hook('request', (event) => {
// Custom request handling
})
})
Examples
Basic Nuxt App
<!-- pages/index.vue -->
<template>
<div>
<h1>Welcome to Nuxt on Deployxa!</h1>
</div>
</template>
With Data Fetching
<!-- pages/index.vue -->
<template>
<div>
<h1>{{ data.title }}</h1>
</div>
</template>
<script setup>
const { data } = await useFetch('/api/data')
</script>
API Route
// server/api/users.ts
export default defineEventHandler(async () => {
return [
{ id: 1, name: 'John' },
{ id: 2, name: 'Jane' }
]
})
Related Topics
Resources
Need Help? Contact support@deployxa.com or join our community Discord.