Running in Node

For this section, you’ll need Node.js, or Node for short, installed on your system. If you don’t already have it, download it from the Node website[44] and verify that it’s in your system path by running the command node --version on the command line.

The transpiled JavaScript code needs the content of the Kotlin JavaScript library that we extracted into the lib directory. Thus, we have to require that first. Then we can load and execute the transpiled file. To make these steps easy, let’s create a JavaScript file:

 kotlin = require(​'./lib/kotlin'​);
 
 require(​'./greet'​)

To run this code, use the command:

 $ ​​node​​ ​​run-in-node.js

Node will load the Kotlin JavaScript runtime file kotlin.js from within the lib directory, and also the transpiled file greet.js, and display the following output on the console:

 hello Jack, Jill

The Kotlin-to-JavaScript transpiler converted the call to println() to console.log();, and thus the output appears on the console when JavaScript is executed.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset