Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including wildcard-subdomains with all npm packages installed. Try it out:

var wildcardSubdomains = require("wildcard-subdomains")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

wildcard-subdomains v1.1.0

Handle dynamic/wildcard subdomains in Express.js


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

namespaceString'_sub'Prepended to the path
whitelistString or Array['www']Subdomains to ignore

Example options:

  namespace: 's',
  whitelist: ['www', 'app'],

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

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

By using the whiteList option, requests to and will be ignored and handled normally.


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

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free