Cover Page

Backend Page

TypeScript with Express

handlers.ts

Change to your chatterd folder and edit the file handlers.ts:

server$ cd ~/reactive/chatterd 
server$ vi handlers.ts

Add one new property to the Chatt interface:

interface Chatt {
    // . . .
    geodata: string | null
}

To the back-end database, geodata is just a string. Since the geodata string optional, we allow its value to be null in TypeScript.

To handle geodata data uploads, make a copy of your postchatt() function inside your handlers.ts file and name the copy postmaps(). Replace the call to chatterDB\INSERT` with:

        await chatterDB`INSERT INTO chatts (username, message, id, geodata) VALUES (${chatt.username}, ${chatt.message}, ${randomUUID()}, ${chatt.geodata})`

which extracts the geodata entry from the JSON object and insert it into the chatts table, along with the rest of its associated chatt.

Next, make a copy of your getchatts() function inside your handlers.ts file and name the copy getmaps(). Replace the declaration of chatts with:

        const chatts = await chatterDB`SELECT username, message, id, time, geodata FROM chatts`.values()

In addition to the original columns, we added reading the geodata column and included it in the chatt data returned to the front end.

We’re done with handlers.ts. Save and exit the file.

main.ts

Change to your chatterd folder and edit the file main.ts:

server$ vi main.ts

Find the initialization of app and add the following new routes for the new APIs /getmaps and /postmaps:

      .get('/getmaps/', handlers.getmaps)
      .post('/postmaps/', handlers.postmaps)

We’re done with main.ts. Save and exit the file.

Build and test run

To build your server, transpile TypeScript into JavaScript:

server$ npx tsc

:point_right:TypeScript is a compiled language, like C/C++ and unlike JavaScript and Python, which are an interpreted languages. This means you must run npx tsc each and every time you made changes to your code, for the changes to show up when you run node.

To run your server:

server$ sudo node main.js
# Hit ^C to end the test

The cover backend spec provides instructions for Testing geodata upload.


Prepared by Sugih Jamin Last updated August 11th, 2025