deno

How to console.log without a newline in Deno?


How do I print a new line to the terminal without a newline in Deno? In node.js I used to do:

process.stdout.write('hello, deno!')

Is this possible in Deno? Deno does not have the process module, and I could not find an equivalent option in https://doc.deno.land/builtin/stable.


Solution

  • I figured it out. Deno does not have node.js's process module but it has different functionality to replicate it. I was able to print to the terminal without a new line with:

    const text = new TextEncoder().encode('Hello, deno!')
    
    // asynchronously
    await Deno.writeAll(Deno.stdout, text)
    
    // or, sychronously
    Deno.writeAllSync(Deno.stdout, text)
    

    Documentation link: https://doc.deno.land/builtin/stable#Deno.writeAll