Socket
Socket
Sign inDemoInstall

vhost

Package Overview
Dependencies
Maintainers
8
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vhost

virtual domain hosting


Version published
Weekly downloads
209K
increased by1.47%
Maintainers
8
Weekly downloads
 
Created

What is vhost?

The vhost npm package is used to create virtual hosts in a Node.js application. It allows you to define different hostnames for different parts of your application, enabling you to serve multiple domains from a single server.

What are vhost's main functionalities?

Basic Virtual Host Setup

This code demonstrates how to set up two virtual hosts using the vhost package. Requests to app1.example.com will be handled by app1, and requests to app2.example.com will be handled by app2.

const express = require('express');
const vhost = require('vhost');
const app = express();

const app1 = express();
app1.get('/', (req, res) => {
  res.send('Hello from app1.example.com!');
});

const app2 = express();
app2.get('/', (req, res) => {
  res.send('Hello from app2.example.com!');
});

app.use(vhost('app1.example.com', app1));
app.use(vhost('app2.example.com', app2));

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

Wildcard Subdomains

This code demonstrates how to use wildcard subdomains with the vhost package. Any subdomain of example.com will be handled by subApp, and the subdomain name will be available in req.vhost.

const express = require('express');
const vhost = require('vhost');
const app = express();

const subApp = express();
subApp.get('/', (req, res) => {
  res.send(`Hello from ${req.vhost[0]}.example.com!`);
});

app.use(vhost('*.example.com', subApp));

app.listen(3000, () => {
  console.log('Server running on port 3000');
});

Other packages similar to vhost

FAQs

Package last updated on 13 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc