-
-
Save karlhorky/7af2aa9b44aad351892f37ce7adbc836 to your computer and use it in GitHub Desktop.
Asynchronous Configuration in Node.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | |
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export const config = {}; | |
export function setPath () { | |
config.path = '/tmp'; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {config} from './2'; | |
console.log('path', config.path); // logs "path /tmp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"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