I would like to create npm TypeScript module that can be used both as command line utility and export methods to be used in other modules.
The problem is that command line utility module needs to contain node shebang (#!/usr/bin/env node) in the first line of index.ts. When such module is imported and referenced in another module the code starts to execute before any exported method is actually called. Example:
#!/usr/bin/env node
const arg1: number = parseFloat(process.argv[2]);
const arg2: number = parseFloat(process.argv[3]);
console.log (superCalc(arg1, arg2)); // this gets called when superCalc() is referenced in another module
export function superCalc(arg1: number, arg2: number) : number {
return arg1 + arg2;
}