Defining the controller

Now that are done with defining the routes and updating the model, we will work on the logic discussed in the Solution design section earlier. Create a new file named cloud-ai-api.ts inside the server/controllers folder. First, we will add the required imports and configure the Cloudinary client as follows:

// SNIPP SNIPPimport * as request from 'request';import * as fs from 'fs';import * as dotenv from 'dotenv';import * as cloudinary from 'cloudinary';import Message from '../models/message';dotenv.config();const API_KEY = process.env.GCP_API_KEY;cloudinary.config({     cloud_name: process.env.CLOUDINARY_CLOUD_NAME,     api_key: process.env.CLOUDINARY_API_KEY,     api_secret: process.env.CLOUDINARY_API_SECRET});// SNIPP SNIPP ...

Get Google Cloud AI Services Quick Start Guide 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.