Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Module / require example #19

Open
bahmutov opened this issue Feb 8, 2018 · 0 comments
Open

Module / require example #19

bahmutov opened this issue Feb 8, 2018 · 0 comments

Comments

@bahmutov
Copy link

bahmutov commented Feb 8, 2018

https://github.com/LeCoupa/awesome-cheatsheets/blob/master/backend/node.js#L77 should be more like

const foo = require('./subfolder/foo.js')
console.log('foo "%s"', foo) // "foo"

// now grab the "module" wrapper around './foo.js'
const fooModule = require.cache[require.resolve('./subfolder/foo.js')]

console.log('foo module', fooModule)
// load module ./bar relative to ./foo
// real path to './bar' is './subfolder/bar'
const bar = fooModule.require('./bar')
console.log('bar "%s"', bar) // "bar"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant