Skip to content

Instantly share code, notes, and snippets.

View LarsDenBakker's full-sized avatar

Lars den Bakker LarsDenBakker

  • ING
  • Amsterdam
View GitHub Profile
@LarsDenBakker
LarsDenBakker / load-config.js
Last active June 5, 2020 08:09
Support esm config in node commonjs projects
const fs = require('fs');
const path = require('path');
const extensions = ['.mjs', '.cjs', '.js'];
async function loadConfig(name) {
// check if node version supports dynamic imports
const supportsEsm = await (async () => {
try {
await import(__filename);