February 2019
Beginner
694 pages
18h 4m
English
If we wrote all handlers for our application in a single file, with an app.get function for each application route, this would become a maintenance headache very quickly. What we really need to do is create a separate module for each of our request handlers, and then reference them from our main application. Luckily, this is very simple using the standard module syntax.
As an example of how to do this, let's create a handler function in a new module file. This file will be named SimpleModuleHandler.ts, as follows:
export function processRequest( req : express.Request, res: express.Response) {
console.log(`SimpleModuleHandler.processRequest`);
res.send('Hello World');
};
Here, we are exporting a function named ...
Read now
Unlock full access