Preparing for this chapter
In this chapter, I continue using the webapp
project from Chapter 6. To prepare for this chapter, replace the contents of the readHandler.ts
file with the code shown in Listing 7.1.
Tip
You can download the example project for this chapter – and for all the other chapters in this book – from https://github.com/PacktPublishing/Mastering-Node.js-Web-Development. See Chapter 1 for how to get help if you have problems running the examples.
Listing 7.1: The contents of the readHandler.ts file in the src folder
import { Request, Response } from "express";
export const readHandler = (req: Request, resp: Response) => {
resp.json({
message: "Hello, World"
});
}
This handler replies to all messages with a response that contains a JSON-formatted object. Replace the contents of the server.ts
file in the src
folder with the code shown in Listing 7.2.
Listing 7.2: The contents...