# Setting up infinite NodeJS servers over HTTPS... For FREE

**URL:** <https://forum.babylonjs.com/t/setting-up-infinite-nodejs-servers-over-https-for-free/50600>\
**Category:** Off topic\
**Tags:** nodejs\
**Created:** [May 16, 2024, 12:42pm UTC](https://forum.babylonjs.com/t/setting-up-infinite-nodejs-servers-over-https-for-free/50600 "2024-05-16T12:42:55Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tricotou](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/tricotou/32/5844_2.png) [@Tricotou](https://forum.babylonjs.com/u/Tricotou)\
**Post date:** [May 16, 2024, 12:42pm UTC](https://forum.babylonjs.com/t/setting-up-infinite-nodejs-servers-over-https-for-free/50600/1 "2024-05-16T12:42:55Z")

</div>

Hello 🙂

Ok so behind this clickbait-like title, I actually want to share something nice with the community 😁

I found a nice way to create as many NodeJS server as I want, (a new server being created within less than a minute) starting from an existing one.  
`Spoiler Alert` : In fact it’s only **one (paid) server** in total of course, there is nothing FREE 😉

* * *

So, here is the trick :

- I have a domain (I pay) at AWS : [tricotools.com](http://tricotools.com)
- Creating any subdomain redirection is FREE. For example :
  - [hover.tricotools.com](http://hover.tricotools.com)
  - [tchat.tricotools.com](http://tchat.tricotools.com)
  - [gpu.tricotools.com](http://gpu.tricotools.com)
  - [game.tricotools.com](http://game.tricotools.com)
  - [vr.tricotools.com](http://vr.tricotools.com)
  - etc, etc…

- I redirect all subdomains toward the same server, using my own `HTTPS certificate`

* * *

Now, here is the nice part :

- On the main server, I have one `folder` for each `child server`. Each folder contains exactly the content of a “normal” NodeJS server : a main file `main.js`, and its dependencies (`public/` folder, `assets/`, or anything…)
- In the root folder, I have a very simple `parent` server :

```javascript
// Requirements
const express = require('express');
const vhost = require('vhost');
const port = process.env.PORT;
const hover_app = require('./hover/main.js').hover_app;
const tchat_app = require('./tchat/main.js').tchat_app;
const gpu_app = require('./gpu/main.js').vr_app;
const game_app = require('./game/main.js').game_app;
const vr_app = require('./vr/main.js').vr_app;

// Express
const App = express();

// Forwarding depending on subdomain
App.use(vhost('hover.tricotools.com', hover_app));
App.use(vhost('tchat.tricotools.com', tchat_app));
App.use(vhost('gpu.tricotools.com', gpu_app));
App.use(vhost('game.tricotools.com', game_app));
App.use(vhost('vr.tricotools.com', vr_app));

// Listen
App.listen(port);

```

The above code redirects automatically each request and connexion toward the considered server, based on the subdomain URL the user is arriving from

On the `child server` side, I simply export an Express App :

```javascript
// Express
const App = express();

// MiddleWares
App.use('middleware_01', params_01);
App.use('middleware_02', params_02);
App.use('middleware_03', params_03);

// Export this App
exports.hover_app = App;

```

And that’s it 🙂

* * *

Is means that now when I have a “new idea”, and want to give it a try over a new “fresh” server (free of anybullshit from another game or whatever) I need to :

- Copy a folder and rename it (5 seconds)
- Add a new `vhost` line in the parent server (5 seconds)
- Commit & Push (20 seconds)
- Connect to AWS Route 53 and redirect this new name (30 seconds)

Total : 1 minute for a new server up and running, over HTTPS 😁

* * *

Maybe all this bullshit sounds obvious for many of you, but on my side I’m quite happy with this new trick. The total RAM used is a few MB in total, the CPU is almost at 0% most of the time… What I mean is, unless I set up a multiplayer game with thousands of people, it does not add any “charge” to the bill 😛

++  
Tricotou
