Your first Node.js app with Kotlin

Miguel Beltran
Mar 19, 2017 · 3 min read

Node is a powerful, JavaScript based, platform for building server side applications with ease. From a Slack Bot to a lightweight REST API or push notification services with Firebase.

Kotlin is a next-generation programming language by the great people of JetBrains, which is gaining popularity with the Android development community as a replacement for old good Java.

I won’t talk about why you might like to consider Kotlin in your Android projects, but rather how can you use Kotlin, instead of JavaScript, to build Node.js applications.

This guide is more aimed for Android developers who want to do a first step into Node.js development, and it is based on my own experiences building a Slack bot with it.

Code available here:


Your first step will be installing Node in your system. Node comes with a handy package manager called npm. Once you have installed Node.js follow these steps to configure your project.

  • On your empty project folder, create a Node project with:
npm init
  • Install the Kotlin dependency:
npm install kotlin --save
  • Finally, for this example, you will create a small REST API using ExpressJS. Add the ExpressJS library with:
npm install express --save

Your Node.js project is now setup. Time to add the Kotlin part.


It is always a good idea to take a look at the official documentation and see how you can setup a Kotlin project to target JavaScript. My recommendation is to use Gradle, rather than an IDEA based project, as we are already familiar with it thanks to Android development. Remember that you’ll need to install Gradle manually.

Your file should look like this:

Setting the kotlinOptions is essential. moduleKind must be set to commonjs to work with Node, and I also recommend to change the outputFile destination to something easy to type.

Your Kotlin source code should be placed in the directory src/main/kotlin/

Let’s create your first Kotlin file here.

In this code example, I load the ExpressJS library, I create a GET endpoint that returns “I am a beautiful butterfly” as response, and listens on port 3000.

Hi! This is Miquel, the author of the post. I hope you like what you are reading!
If you are looking for a freelance Android developer, look no further!
Check: and I’ll be happy to chat with you!

Let’s run

First, you’ll have to compile your Kotlin code to JS with Gradle.

gradle build

A JavaScript file will be generated in node/index.js which contains your Kotlin code compiled to JavaScript.

Now, start your Node server.

node node/index.js

It works! You can go to http://localhost:3000 to check that your server is running.

In Summary

Kotlin is not the only language that can be compiled to JavaScript, but it’s a language that you might already know thanks to it’s increasing popularity among Android developers. If it happens that you are already playing with it, now you have no excuse to explore other usages.

If you are an independent Android developer, having the power to quickly create micro-services can help you a lot to enhance your applications.

As you saw by this guide, building a small service took minutes, with barely any boilerplate code and you can use the same IDE you are already familiar with.

Thanks for getting this far! I hope I have inspired you to give Node.js a try.

Miguel Beltran

Written by

Freelance Mobile Developer for Android and Flutter.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade