If I understand correctly, with the release of Kotlin 1.1, we can set JavaScript as a compile target for full compilation to JavaScript of Kotlin projects. Is it possible (or feasible) to write an entire Node.js application, such as an express webserver, using only Kotlin code?
As this question suggests, we can import Node modules into Kotlin classes:
external fun require(module: String): dynamic
val express = require('express')
...which seems like I can create an application using:
val app = express()
Is this the Kotlin way to set up an express application? Or should I declare a class as described in the docs:
@JsModule("express")
external class Express { ... }
What is the canonical way to set up a Kotlin project for Node.js application development? Is Kotlin's JavaScript interoperability robust enough to continue down this path, or will it be more trouble than it's worth?
If Node. js is already installed on the host where you build Kotlin/JS projects, you can configure the Kotlin/JS Gradle plugin to use it instead of installing its own Node.
Can you build web applications with Kotlin? Although Kotlin is well-known among developers as a language for building Android apps and backends, it's also great for building web apps.
Kotlin is supported by the official integrated development environment (IDE) for Android development, Android Studio. So programmers can easily use Kotlin's code when working on Android development.
Kotlin/JS frameworksYou can use both reactive and imperative programming models to build your frontend, use connectors for Ktor, Spring Boot, and other frameworks to integrate it with your server-side applications, and share code using Kotlin Multiplatform.
Technically speaking, yes, provided the claim by Kotlin that:
You can use Kotlin to interact with server-side JavaScript such as node.js
Is correct, and the transpilation of Kotlin -> JS is reliable enough to be able to predict what JS is coming out, then you could write a Node app in Kotlin, much as you can write them in TypeScript.
I suspect, personally, that you'd find it difficult, buggy, and rather short on support, but it might make a good academic exercise...maybe.
Yes, it's possible https://kotlinlang.org/docs/reference/js-project-setup.html
But, NIO was the biggest reason to use NodeJS instead of any language to build a backend solution. Now, with reactive first class support you can have a stack like Kotlin + Spring Reactive + Coroutines + R2DBC and build a simple micro service or any full enterprise solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With