Q:

Node / JS create new instance right upon import

I want to make an instance of a class without importing the class first and making new afterwards.
Instead of 
var mainClass = require('../dist/main'); // has "class Main { ... }"
var mainInstance = new mainClass();

I want
var mainInstance = new require('../dist/main').Main();

But something with the syntax is wrong.
var main = new require('../dist/main').Main();
                                       ^
TypeError: Class constructor Main cannot be invoked without 'new'

Is this even possible? I use a combination of TypeScript and plain JS.

A:

You can use parenthesis to achieve that:
var main = new (require('../dist/main').Main)();

And if your module.exports was solely exporting a class you'd do it like following:
var main = new (require('../dist/main'))();

