Kolin Multiplatform Targets NodeJS

Submitted by Dickens A S on Sat, 08/08/2020 - 12:13

Code written in kotlin will get transformed to JavaScript NPM module which can be executed directly from Node.JS

Simple Kotlin code

fun main() {
   println ("hello")

The test1 function code

fun test1() {
   println ("hello test1")

The package.json which is manually created at root folder of the project

 "private": true,
 "workspaces": [
 "devDependencies": {},
 "dependencies": {},
 "peerDependencies": {},
 "optionalDependencies": {},
 "bundledDependencies": [],
 "name": "js-nodejs",
 "version": "1.0.0",
 "scripts": {
  "start": "node build\\js\\packages\\js-nodejs\\kotlin\\js-nodejs.js"

build\\js\\packages\\js-nodejs --- this js-nodejs is the project name, it needs to be changed if you have a different project name


 NodeJS Execution from command prompt

C:\js-nodejs>npm start

> js-nodejs@1.0.0 start C:\js-nodejs
> node build\js\packages\js-nodejs\kotlin\js-nodejs.js

hello test1

Here, the npm start command picks up the package.json "scripts" -> "start" 

Source Code

End Of Article

Add new comment