Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
64 lines (40 sloc) 2.02 KB


Build Status npm version

Handle dynamic/wildcard subdomains in Express.js. Perfect for when you have customized subdomains for different users, and need to handle them within your Node app.

Requests to can be handled with using the route /_sub/:subdomain

Paths and query strings and paths remain intact. For example: can be handled with using the route /_sub/foo/post/cat?oh=hai

Dependency free!

How to use

Require the module in app.js:

var wildcardSubdomains = require('wildcard-subdomains')

Use the module in middleware:


opts - Object

Key Type Default Description
namespace String '_sub' Prepended to the path
ignore String '' Ignore url if its first subdomain matches ignore
stripSubdomain String '' Find and remove subdomain matching stripSubdomain

Example options:

  namespace: 's',
  ignore: 'app',

Handle the new route for your subdomain, for example would be handled with:

app.get('/s/foo/', function(req, res){


npm run example

Or check the examples directory in this repo


For testing subdomains locally, use the domain

This is a domain that points back to your localhost, allowing you to test subdomains like

Running your app behind a proxy? You'll likely need to set the appropriate trust proxy in express

You can’t perform that action at this time.