Maybe this is a dumb question, but what's the easi...
# javascript
j
Maybe this is a dumb question, but what's the easiest way to get the equivalent of Kotlin/JVM's
readLine()
in Kotlin/JS (nodejs target)?
v
I guess using
readline
module from node.js, targeting
process.stdin
?
j
I tried that, but I'm also very new to Kotlin/JS and node. I'm doing this:
Copy code
implementation(npm("readline", "17.4.0"))
but getting this:
Copy code
Couldn't find any versions for "readline" that matches "17.4.0"
maybe
readline
isn't a "module" in the sense of dependency? In which case I need to pull it in differently?
v
Nah, that would install a package named
readline
from npm which is only available in version 1.3.0 and renamed due to the node.js included module called
readline
.
j
Got it -- So do I need this syntax?
Copy code
import * as readline from 'node:readline';
and if so, where do I put that in Kotlin?
v
You want
org.jetbrains.kotlinx:kotlinx-nodejs
as normal dependency if you don't have it yet. And then you can just do
import readline
and use it iirc
j
Awesome I will try that. Thanks for your help!
v
yw
Or if you are on Kotlin 1.6, just use
readln
that is fully cross-platform: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.io/readln.html
j
Sadly:
Copy code
Currently this function is not supported in Kotlin/JS and throws UnsupportedOperationException.
😕
v
Hm, why is it marked as supported then at all? o_O