Skip to content

Instantly share code, notes, and snippets.

@karlhorky
Last active April 6, 2018 05:25
Show Gist options
  • Save karlhorky/7af2aa9b44aad351892f37ce7adbc836 to your computer and use it in GitHub Desktop.
Save karlhorky/7af2aa9b44aad351892f37ce7adbc836 to your computer and use it in GitHub Desktop.
Asynchronous Configuration in Node.js
import {setPath} from './2';
(async () => {
await setPath();
// Could also do dynamic import() here with https://github.com/airbnb/babel-plugin-dynamic-import-node
require('./3');
})();
export const config = {};
export function setPath () {
config.path = '/tmp';
}
import {config} from './2';
console.log('path', config.path); // logs "path /tmp"
{
"scripts": {
"one": "node -r babel-register 1.js"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment