The syntax of the array in the [module]
should be updated to module
.
Moreover, it is recommended to utilize conditional importing for only importing the specific module you need. Keep in mind that since import
returns a promise, make sure to place the code within an async
function and use await
before each import
statement as shown below:
async function invokeHttpRequest() {
const module = (options.port === 443 ? await import("https") : await import("http"));
const req = module.request(options, (res) => {
console.log(res.statusCode);
});
}