What is the right way to call Scala.js from Node.js? The code below does work, but I don't like the .__ScalaJSExportsNamespace in the require line in run.js. Also is it important for me to get the text "someTest() called!" actually printed on my terminal.
run.js
var fastopt = require('./scalajs-hello-world-fastopt').__ScalaJSExportsNamespace;
var run = fastopt.RunMe();
run.main();
console.log(run.helloWorld());
console.log(run.someTest());
RunMe.scala
import scala.scalajs.js.annotation._
import scala.scalajs.js.JSApp
@JSExportAll
object RunMe extends JSApp {
def main(): Unit = {
println("Hello from main()!")
}
def helloWorld() = "Hello from helloWorld()!"
def someTest() = {
println("someTest() called!")
s"In Scala.js, (1.0).toString is ${(1.0).toString}!"
}
}
Output
$ node run
Hello from main()!
Hello from helloWorld()!
someTest() called!
In Scala.js, (1.0).toString is 1!