Specifying the router

We need to write a behavior in the route.kt file. This will let the server know which page to load when any request hits the server. The router.kt file will look like this:

    fun router() {      val express = require("express")      val router = express.Router()      router.get("/", { req, res ->       res.render("index")      })      return router    }

This simply means that whenever a get request with no name approaches the server, it should display an index page to the user. We are told to instruct the framework to refer to the router.kt file by writing the following line of code:

    app.use("/", router())

Get Kotlin Blueprints now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.