3

I am starting a project in Kotlin-Multiplatform. Accessing the resource folder via Java is quite easy, but I don't know how to access it via JS targeting Node.

During testing, I found out that the resource file is stored in a separate folder. If I'm not mistaken:

build/js
  |-- package
  |   |--project
  |   |--project-test \\tests are executed here via calling __dirname in node
  |
  |--processedResources 
      |-- testfile.txt \\ files in the resource folder are stored here

I would like to know: how is it done via JS/Node?

medavox
  • 175
  • 2
  • 11

1 Answers1

1

You can try to use fs:

external fun require(name: String): dynamic
external val __dirname: dynamic

val fs = require("fs")
val path = require("path");

fun main() {
    val path = path.join(
        __dirname,
        "..\\..\\..\\..",
        "processedResources",
        "js",
        "main",
        "test.txt"
    )
    println(fs.readFileSync(path, "utf8"))
}

vanyochek
  • 815
  • 4
  • 10