Performance: Self-hosting with Node.js
MEDIUM IMPACT
This affects the server response time and initial page load speed by controlling how the Next.js app is served and assets are delivered.
import { createServer } from 'http'; import { parse } from 'url'; import next from 'next'; const app = next({ dev: false }); const handle = app.getRequestHandler(); app.prepare().then(() => { createServer((req, res) => { const parsedUrl = parse(req.url, true); handle(req, res, parsedUrl); }).listen(3000, () => { console.log('> Ready on http://localhost:3000'); }); });
const express = require('express'); const next = require('next'); const app = next({ dev: true }); const handle = app.getRequestHandler(); app.prepare().then(() => { const server = express(); server.all('*', (req, res) => { return handle(req, res); }); server.listen(3000, () => { console.log('> Ready on http://localhost:3000'); }); });
| Pattern | Server Response | Bundle Size | LCP Impact | Verdict |
|---|---|---|---|---|
| Dev mode self-hosting | Slow (200-500ms delay) | Large (unminified bundles) | High delay | [X] Bad |
| Prod mode self-hosting | Fast (50-100ms delay) | Small (minified bundles) | Low delay | [OK] Good |