The recommended way to use Kotlin/JS is via the
Use cases for Kotlin/JS
There are numerous ways to use Kotlin/JS. Here is a non-exhaustive list of scenarios in which you can use Kotlin/JS:
Write frontend web applications using Kotlin/JS
Kotlin/JS allows you to leverage powerful browser and web APIs in a type-safe fashion. Create, modify, and interact with the elements in the Document Object Model (DOM), use Kotlin code to control the rendering of
canvasor WebGL components, and enjoy access to many more features that modern browsers support.
Write full, type-safe React applications with Kotlin/JS using the
kotlin-wrappersalso provides support for a select number of adjacent technologies, like
Use the Kotlin/JS frameworks, which take full advantage of Kotlin concepts and its expressive power and conciseness.
Write server-side and serverless applications using Kotlin/JS
kotlinx-nodejs, you have typesafe access to the Node.js API directly from your Kotlin code.
Use Kotlin's multiplatform projects to share code with other Kotlin targets
All the functionality of Kotlin/JS can also be accessed when using the Kotlin
If your backend is written in Kotlin, you can share common code such as data models or validation logic with a frontend written in Kotlin/JS, which allows you to write and maintain full-stack web applications.
You can also share business logic between your web interface and mobile apps for Android and iOS, and avoid duplicating commonly used functionality, like providing abstractions around REST API endpoints, user authentication, or your domain models.
Of course, this is not a complete list of all the ways you can use Kotlin/JS to your advantage, but merely some cherry-picked use cases. We invite you to experiment with different combinations and find out what works best for your project.
Modern web development benefits significantly from frameworks that simplify building web applications. Here are a few examples of popular web frameworks for Kotlin/JS written by different authors:
KVision is an object-oriented web framework that makes it possible to write applications in Kotlin/JS with ready-to-use components that can be used as building blocks for your application's user interface. You 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.
Visit https://kvision.io for documentation, tutorials, and examples.
fritz2 is a standalone framework for building reactive web user interfaces. It provides its own type-safe DSL for building and rendering HTML elements, and it makes use of Kotlin's coroutines and flows to express components and their data bindings. It provides state management, validation, routing, and more out of the box, and integrates with Kotlin Multiplatform projects.
Visit https://www.fritz2.dev for documentation, tutorials, and examples.
Visit https://nacular.github.io/doodle/ for documentation, tutorials, and examples.
Compose for Web
Compose for Web, a part of Compose Multiplatform, brings Google's Jetpack Compose UI toolkit to your browser. It allows you to build reactive web user interfaces using the concepts introduced by Jetpack Compose. It provides a DOM API to describe your website, as well as an experimental set of multiplatform layout primitives. Compose for Web also gives you the option to share parts of your UI code and logic across Android, desktop, and the web.
You can find more information about Compose Multiplatform on its landing page.
Kotlin/JS, Today and Tomorrow
In this video, Kotlin Developer Advocate Sebastian Aigner explains the main Kotlin/JS benefits, shares some tips and use cases, and talks about the plans and upcoming features for Kotlin/JS.
Get started with Kotlin/JS
If you're new to Kotlin, a good first step is to familiarize yourself with the basic syntax of the language.
Tutorials for Kotlin/JS
Build a web application with React and Kotlin/JS — tutorial guides you through the process of building a simple web application using the React framework, shows how a type-safe Kotlin DSL for HTML makes it easy to build reactive DOM elements, and illustrates how to use third-party React components and obtain information from APIs, all while writing the whole application logic in pure Kotlin/JS.
Build a full-stack web app with Kotlin Multiplatform teaches the concepts behind building an application that targets Kotlin/JVM and Kotlin/JS by building a client-server application that makes use of shared code, serialization, and other multiplatform paradigms. It also provides a brief introduction to working with Ktor both as a server- and client-side framework.
Sample projects for Kotlin/JS
Full-stack Spring collaborative to-do list shows how to create a to-do list for collaborative work using
kotlin-multiplatformwith JS and JVM targets, Spring for the backend, Kotlin/JS with React for the frontend, and RSocket.
Kotlin/JS and React Redux to-do list implements the React Redux to-do list using JS libraries (
react-redux) from npm and Webpack to bundle, minify, and run the project.
Full-stack demo application guides you through the process of building an app with a feed containing user-generated posts and comments. All data is stubbed by the fakeJSON and JSON Placeholder services.
New Kotlin/JS IR compiler