'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 1:[1]
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
Solution 2:[2]
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.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | |
Solution 2 | 17xande |