Express API endpoints

In order to provide the data that we have stored in our database to our application, we will create a set of REST endpoints in our Express server that will connect to our database, execute a SQL query, and return data as JSON objects. In order to work with an Sqlite3 database, we will use the sqlite3 node library, which can be installed as follows:

npm install sqlite3
npm install @types/sqlite3 --saveDev   

In order to serve data to our application, we will create a new Express handler in the express/routes directory named dataRoutes.ts as follows:

import * as express from 'express'; import { serverLog } from '../main'; var router = express.Router(); router.get(`/boards`, async (req: any, res: any, next: any) => { serverLog(`GET ...

Get Mastering TypeScript 3 - Third Edition 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.