title: How can i make a subdomain automatically when a user register
body: <p>Hi i tried everywhere but i cant get the solution. i am using vhost and nodejs to make subdomain in vhost documentation they not provided how to make subdomain dynamically <strong>my actual question is how can i make a subdomain with the name of the user after the user signup</strong></p>
  <p>i make subdomain manually and the code is below</p>
  <pre><code>const express = require(&quot;express&quot;);
  const app = express();
  const morgan = require(&quot;morgan&quot;);
  var cookieParser = require(&quot;cookie-parser&quot;);
  const vhost = require(&quot;vhost&quot;);
  
  
  app.use(cookieParser());
  
  const institute_adminRoutes = require(&quot;./api/routes/institute-admin&quot;);
  
  app.use(
    cors({ origin: &quot;*&quot;, credentials: true, exposedHeaders: [&quot;set-cookie&quot;] })
  );
  app.use(morgan(&quot;dev&quot;));
  app.use(bodyParser.urlencoded({ extended: false }));
  app.use(bodyParser.json());
  
  
  const subdomain = express();
  
  const domain = &quot;localhost&quot;;
  
  
  app.use(vhost(`jhon.${domain}`, subdomain,));    *//here is the subdomain i create with name jhon*
  
  subdomain.use(cookieParser());
  
  subdomain.use(morgan(&quot;dev&quot;));
  subdomain.use(bodyParser.urlencoded({ extended: false }));
  subdomain.use(bodyParser.json());
  
  subdomain.use(institute_adminRoutes);
  
  app.use(&quot;*&quot;, (req, res, next) =&gt; {
    const error = new Error(&quot;Not found&quot;);
    error.status = 404;
    next(error);
  });
  
  app.use(&quot;*&quot;, (error, req, res, next) =&gt; {
    res.status(error.status || 500);
    res.json({
      error: {
        message: error.message,
      },
    });
  });
  
  module.exports = app;
  </code></pre>
  <p>Here i create it manually with name jhon  <code>app.use(vhost(</code>jhon.${domain}<code>, subdomain,));</code></p>
  <p><strong>how can i do it by taking the name of the user after signup</strong></p>