Can I use alias with NodeJS require function?
Sure, just use the object destructuring syntax:
const { old_name: new_name, foo: f, bar: b } = require('module');
It is possible (tested with Node 8.9.4):
const {foo: f, bar: b} = require('module');
console.log(`${f} ${b}`); // foo bar
Yes, a simple destructure would adhere to your request.
Instead of:
var events = require('events');
var emitter = new events.EventEmitter();
You can write:
const emitter = {EventEmitter} = require('events');
emitter()
will alias the method EventEmitter()
Just remember to instantiate your named function: var e = new emitter();
😁