Is there a way I can use kotlin for firebase cloud functions?? I'm currently working on a project like uber and running out of time seriously, I'm familiar with kotlin but know nothing about JavaScript or type script.
I really would love it if it's possible to do it with kotlin
A quick search on Google reveals this article. https://medium.com/@ishaqhassan/firebase-cloud-functions-using-kotlin-55631dd43f67
You need to start a Kotlin project and set it to compile in JavaScript. Then in build.gradle set this
compileKotlin2Js.kotlinOptions {
moduleKind = "commonjs"
outputFile = "functions/index.js"
}
This will tell the gradle to output the transpiled code in functions/index.js path where firebase is storing its functions by default.
Some code example from the link
external fun require(module:String) : dynamic
external var exports: dynamic
fun main(args: Array<String>) {
val fireFunctions = require("firebase-functions")
exports.myTestFun = fireFunctions.https.onRequest { request , response ->
response.send("Hi from kotlin!")
}
}
So it's possible, as with this approach, Kotlin is compiled in JavaScript, but i am not sure how easy it is to use/deploy.
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