admin管理员组文章数量:1327689
If I understand correctly, with the release of Kotlin 1.1, we can set JavaScript as a pile target for full pilation 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 I understand correctly, with the release of Kotlin 1.1, we can set JavaScript as a pile target for full pilation 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?
Share Improve this question asked Oct 16, 2017 at 17:31 Cy RossignolCy Rossignol 16.9k5 gold badges60 silver badges88 bronze badges 10- 6 Why would you want to do that? – Jared Smith Commented Oct 16, 2017 at 17:35
- 2 @JaredSmith I guess I'm partly asking the same question... "should I want to do this?" I know there are other options, but I'm particularly interested in exploiting Kotlin's type-safety while improving my skills in a relatively expressive and runtime-agnostic language that I can apply to other types of projects. – Cy Rossignol Commented Oct 16, 2017 at 17:39
- 1 I'm going to argue that Javascript/Typescript and Kotlin are not sufficiently different in expressive power to make a purely language-based argument for one over the other (although Kotlin definitely gets the edge in the library department courtesy of Java). So what you are really asking is "should I use V8 or the JVM". I don't feel qualified to answer that, but unless you have very good reasons stick with the one that brought you to the dance. Its probably not worth the trouble vs. just flat-out switching to JavaScript/TypeScript... or sticking with Kotlin/JVM. – Jared Smith Commented Oct 16, 2017 at 17:43
- @JaredSmith Well, I'm more interested in the possibility of this approach rather than its correctness as defined by the availability of existing technologies in this area. Kotlin is a relatively new language/ecosystem, so it may bee a valid alternative for node development in the future. I agree with what you're saying and appreciate the input--if I needed to pick a language for an enterprise project, I'd certainly choose an industry-standard set of tools. But Kotlin seems to support the goal of the question, at least to some degree, so I'm interested to see how far this approach works. – Cy Rossignol Commented Oct 16, 2017 at 18:18
- 1 I guess my question remains why? What does Kotlin by you over JavaScript in a node.js environment? Lots of languages can be varying degrees of easily piled to JS: clojure, haskell, ocaml, C/C++. Indeed, one can write node modules in another language and expose them to node via FFI (David Herman at Mozilla had a blog post about doing so in Rust). It's certainly possible, and it may even be easy, I'm just not sure what benefit accrues. – Jared Smith Commented Oct 16, 2017 at 20:51
2 Answers
Reset to default 3Technically 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 ing 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/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.
本文标签: javascriptIs it possible to build a full Nodejs web application using KotlinStack Overflow
版权声明:本文标题:javascript - Is it possible to build a full Node.js web application using Kotlin? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742216803a2434715.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论