Code in TypeScript is compiled to JavaScript when you save it, and runs on the runtime you choose in Sandbox Settings : Node.js (the default) or Bun, in the version you pick there, with only the npm packages you add.
In short
Write async function main(g) and export it : module.exports = main.
The code, the global object g, utility classes, types and the examples of g.sys are the same on both : switching the runtime needs no change of code, unless the code uses something only one runtime has (Bun.file).
A file, a picture, a PDF : return its bytes (a Buffer, or any Uint8Array : Buffer.from(await answer.arrayBuffer()) for what fetch downloaded), or put them in g.res.output, and name their kind of content. The answer is those bytes as they are, whatever the kind of content, with the headers of the code. (A text under a kind of bytes, image/gif, is read as base64.)
import*asTfrom'types';asyncfunctionmain(g:T.IAMGlobal){if(!g.req.body.quantity){throw[{code:T.EStatusCode.BAD_REQUEST,message:`'quantity' is missing.`}];}return{ok:true};}module.exports=main;
import*asTfrom'types';asyncfunctionmain(g:T.IAMGlobal){g.logger.log('order ',7,' paid');console.log('kept in the console of the account');g.shared.calls=(g.shared.calls||0)+1;// lives as long as the runnerg.res.shared.started=true;// travels with this request : pre hook → API → post hookreturng.shared.calls;}module.exports=main;
Code in TypeScript imports the utility classes written in TypeScript on both runtimes (import { Tax } from 'utils/Tax';), and they import each other and your packages. A class written in another language is for the code of that language.
Turn debugging on in the debug settings, set a breakpoint in the margin of the editor and send the request : the code stops on the line of your TypeScript, on Node.js and on Bun alike (its source map is applied for you), and the Debug tab of the API testing page shows its variables and its console.