To host multiple Node.js sites on the same IP/server with different domains, we call the listen method with the domain.
For instance, we write
const server = require("diet");
const app = server();
app.listen("http://example.com/");
app.get("/", ($) => {
$.end("hello world ");
});
const sub = server();
sub.listen("http://subdomain.example.com/");
sub.get("/", ($) => {
$.end("hello world at sub domain!");
});
const other = server();
other.listen("http://other.com/");
other.get("/", ($) => {
$.end("hello world at other domain");
});
to create the server with the diet package.
Then we call listen with the domain or subdomain URL to list to request to.
We call get with each server to listen for get request from /.