I have a node library with multiple scripts (ES modules to be precise). One of the module, when invoked, uses exec
function from built-in child_process
module. I need to run ts-node
command using the exec
function.
The problem is that ts-node
is not recognized as exec
doesn't do the path manipulation magic that npm scripts
do by appending the node_modules/.bin
to the path
variable. Further, I cannot rely on __dirname
and __filename
special values as I use ESM and not CJS (I know there is a way to get these values but I would rather prefer if there is any standard approach to execute commands with the semantics of npm scripts
).
So, how can I execute ts-node
command from my own script which could be installed anywhere (as a nested dependency)?