In python, in order to expose top-level functionality in a package, one would create an __init__.py
#__init__.py
from .implmentation import impl_function
def exposed_fn():
"""call impl_function
Which would expose exposed_fn
as the main function to use when importing a directory (package). What's the equivlalent of this in javascript's require
?
Obviously you can do the following.
//init.js?
var impl_function = require('./implmentation.js').impl_function;
var exposed_fn = function () {//call impl_function ...};
//Will expose `exposed_fn` when requiring this file.
module.exports = {
exposed_fn: exposed_fn
}
//How to expose `expose_fn` when requiring a this folder?????
Is there an equivalent? All searches so far haven't proved fruitful.
Using an index.js
file in the same manner seems to work. If you export objects from an index.js
file they can be accessible at the folder level.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With