either run goal clerk compile myprogram.teal and then in the JS read the file myprogram.teal.tok,
or use the .compile function of an algod V2 client (for that you need your algod endpoint to have the flag EnableDeveloperAPI set to true - Algorand Developer Docs).
// helper function to compile program source
async function compileProgram(client, programSource) {
let encoder = new TextEncoder();
let programBytes = encoder.encode(programSource);
let compileResponse = await client.compile(programBytes).do();
let compiledBytes = new Uint8Array(Buffer.from(compileResponse.result, "base64"));
return compiledBytes;
}