How to console.log without a newline in Deno?

Viewed 1614

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.

2 Answers

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

import { writeAllSync } from "https://deno.land/std/streams/conversion.ts";

const text = new TextEncoder().encode('Hello')
writeAllSync(Deno.stdout, text)

Deno.writeAllSync and Deno.writeAll are deprecated, it's recommended to use the package above instead.

Related