With node.js, can I make some functions available without import, for a DSL?

49 Views Asked by At

I'm trying to use Javascript and Node.js to create a DSL for a certain application. I'd like my files have certain predefined functions available, without having to import them.

Example file: dsl_script.js:

doStuff(1, 2);
var foo = makeFoo()

In Python, I know how to do this. You can hook into the import machinery and add the bindings for doStuff and makeFoo to the module's dictionary (symbol table) before you execute the code in the module file itself.

But in Javascript the only way I know to do this is add some lines to the top of every file. Something like this:

import {doStuff, makeFoo} from 'builtins'; 

Is there a way to make some stuff available by default without explicit import?

0

There are 0 best solutions below