How to run kotlinc-js compiled javascript in nodejs?

I’m write small utility in kotlin for javascript:

Next, I try to compile it:

kotlinc-js -module-kind plain ./SquareJS.kt -output run.js

File run.js appears here. This file need kotlin dependency. I found kotlin.js inside kotlin-stdlib-js.jar in lib folder of compiler.

I try to run:

node kotlin.js kotlin.meta.js run.js

But nothing happens. So, how to run compiled javascript by kotlin properly in node?

I found an article, “Your first Node.js app with Kotlin”, that says:

moduleKind must be set to commonjs to work with Node

So maybe thats the problem because it looks like you are using plain as moduleKind.

No, I’m trying all 4 module kinds, no one works.

May be kotlin.js need be included somehow else?

Node.js uses node_modules directory to search for dependencies.

You can place kotlin.js inside ./node_modules/ manually.
Alternatively npm install kotlin will do this for you.

After that you’ll be able to run: node run.js

Note: you want to use umd or commonjs module kinds to run Kotlin/JS in Node.js