{"id":18360,"library":"express-subdomain","title":"express-subdomain","description":"Simple and lightweight middleware for handling subdomains in Express.js applications. Current stable version is 1.0.6, with minimal releases since initial publication. Key differentiators: zero dependencies, supports multi-level subdomains, wildcards, and chaining. Simpler than alternatives like vhost, focusing only on subdomain routing without virtual hosting features.","status":"maintenance","version":"1.0.6","language":"javascript","source_language":"en","source_url":"git://github.com/bmullan91/express-subdomain","tags":["javascript","express","express-subdomain","subdomain","typescript"],"install":[{"cmd":"npm install express-subdomain","lang":"bash","label":"npm"},{"cmd":"yarn add express-subdomain","lang":"bash","label":"yarn"},{"cmd":"pnpm add express-subdomain","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; middleware operates on Express request/response objects","package":"express","optional":true}],"imports":[{"note":"ESM-only; package ships TypeScript types but no CommonJS support","wrong":"const subdomain = require('express-subdomain')","symbol":"default","correct":"import subdomain from 'express-subdomain'"},{"note":"Default export only; named import is incorrect","wrong":"import { subdomain } from 'express-subdomain'","symbol":"subdomain","correct":"import subdomain from 'express-subdomain'"},{"note":"CJS requires default assignment; destructured import does not work","wrong":"const { subdomain } = require('express-subdomain')","symbol":"subdomain","correct":"const subdomain = require('express-subdomain')"}],"quickstart":{"code":"import express from 'express';\nimport subdomain from 'express-subdomain';\n\nconst app = express();\nconst apiRouter = express.Router();\n\napiRouter.get('/', (req, res) => {\n  res.send('Welcome to API');\n});\n\napp.use(subdomain('api', apiRouter));\n\napp.get('/', (req, res) => {\n  res.send('Homepage');\n});\n\napp.listen(3000, () => console.log('Server running on port 3000'));","lang":"typescript","description":"Demonstrates basic subdomain routing with Express Router and wildcard subdomain middleware."},"warnings":[{"fix":"Ensure app.use(subdomain(...)) is placed before app.get('/', ...).","message":"Subdomain middleware must be registered before other routes that match the base domain, otherwise Express may match base routes first.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Use explicit multi-level subdomain strings like 'v1.api' or chain subdomain middleware for deeper nesting.","message":"Wildcard subdomains (e.g., '*.api') match any single subdomain part, not multi-level wildcards.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Add entries to /etc/hosts or use tools like ngrok to test subdomains.","message":"Subdomain resolution depends on the Host header; local development requires proper hosts file entries (e.g., 'subdomain.localhost' may not work).","severity":"gotcha","affected_versions":">=1.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run 'npm install express-subdomain' and use 'import subdomain from 'express-subdomain'' in ESM code.","cause":"Package not installed or used in a non-ESM context without proper import.","error":"Cannot find module 'express-subdomain'"},{"fix":"Use 'import subdomain from 'express-subdomain'' (default import) instead of 'import { subdomain }...'.","cause":"Attempted to use named import instead of default import.","error":"TypeError: subdomain is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}