Instructions to configure Typescript in Catalyst NodeJS advancedio function

Instructions to configure Typescript in Catalyst NodeJS advancedio function

Prerequisites: Catalyst CLI should be installed and a Catalyst project should be initialized in a folder in your local machine.
Then you can follow the below steps:
1. Create a new advanced function by running the command from your project directory
  1. catalyst functions:add
2. Navigate inside your function directory (functions/{your function name}) and then run the command 
  1. npm install typescript --save-dev  
  2. npm i --save-dev @types/express  
3. Create a folder named src and create an index.ts file inside it.
4. You can code your logic in index.ts (you can also refer the code snippet at the end)
5. Include the below script in package.json before “dependencies” key.

For MacOS & Linux :
  1. "scripts": {
  2. "init":"./node_modules/.bin/tsc --init",
  3. "build": "./node_modules/.bin/tsc",
  4. "watch": "./node_modules/.bin/tsc --watch"
  5. }
For Windows :
  1. "scripts": {
  2. "init":"node_modules\\.bin\\tsc --init",
  3. "build": "node_modules\\.bin\\tsc",
  4. "watch": "node_modules\\.bin\\tsc --watch"
  5. }
6. Run the below command to initialise the typescript project
  1. npm run init
7. Modify the below fields in tsconfig.json
  1. "rootDir": "./src", 
  2. "outDir": "./build"  
Add your remaining configurations
8. Create a folder named build inside functions/{your_function_name} directory and modify the below code in your catalyst-config.json
  1. "execution": {
  2. "main": "build/index.js"
  3. }
9. Include the below script inside functions key in catalyst.json file present in your root directory

For MacOS & Linux :
  1. "scripts": {
  2. "{your function name}": "cd {your function name} && rm -rf build && npm run build",
  3. "preserve": "catalyst run functions:{your function name}",
  4. "predeploy": "catalyst run functions:{your function name}"
  5. }
For Windows :
  1. "scripts": {
  2. "{your function name}": "cd {your function name} && del build\\* && npm run build",
  3. "preserve": "catalyst run functions:{your function name}",
  4. "predeploy": "catalyst run functions:{your function name}"
  5. }
10. Navigate to your (functions/{your function name}) directory in the terminal and run the command
  1. npm run watch
11.Open another terminal window and navigate to your project directory in the terminal and run the command in order to serve your function
  1. catalyst serve 
You can run catalyst deploy in order to deploy your application to the development environment.

// sample index.ts code snippet for reference
  1. "use strict";
  2. import catalyst from "zcatalyst-sdk-node";
  3. import express, { Express, Request, Response } from "express";
  4. const app: Express = express();
  5. app.use((req, res, next: any) => {
  6.   console.log("Req", req.method);
  7.   res.header("Access-Control-Allow-Origin", "*");
  8.   next();
  9. });
  10. app.post("/cache", async (req: Request, res: Response) => {
  11.   try {
  12.     const catalystApp = catalyst.initialize(req as Record<string, any>);
  13.     //Insert Cache by passing the key-value pair
  14.     let cache = catalystApp.cache();
  15.     let segment = cache.segment();
  16.     let cachePromise = segment.put("Name", "Linda McCartney");
  17.     cachePromise.then((entity) => {
  18.       console.log(entity);
  19.       res.status(200).send(entity);
  20.     });
  21.   } catch (err) {
  22.     res.status(500).send(err);
  23.   }
  24. });
  25. module.exports = app;

    • Announcements

    • React Nexus 2025 Recap: Catalyst Slate in Action!

      Hey Catalyst Community! We recently attended the React Nexus 2025 conference, an exciting gathering for frontend enthusiasts and React developers. Our team had an incredible time presenting and conducting a hands-on workshop on Catalyst Slate, our streamlined
    • [Webinar] A hands-on guide to Catalyst Stratus

      Have you used Catalyst Stratus yet? It’s an object storage service that makes it easy to handle large files — whether they're coming from your Catalyst app or other Zoho apps. We’re hosting a live coding session where you’ll build a working prototype
    • Catalyst Video Tutorials!

      Hello everyone! We’ve been brewing something exciting behind the scenes, and we’re thrilled to finally share it with you- Catalyst video tutorials are here! We recognized that videos are the predominant medium for learning and discovery these days, so
    • [Webinar] Catalyst Cloud Browser in Action: PDF & Web Rendering Solutions for Regulated Industries

      Hi everyone, Have you ever struggled with rigid PDF tools or clunky rendering logic in BFSI or healthcare apps? Do your clients struggle to deliver compliant, dynamic, and automated documents — and most are still stuck with brittle, server-heavy PDF generation?
    • Announcing Catalyst Developer Bootcamps in India - Zoho Community

      Hey everyone! We're excited to announce a set of developer bootcamps dedicated to Catalyst! These bootcamps are aimed to empower developers to build, scale, and deploy applications with speed and precision, using Catalyst. Whether you're a newcomer or

      Catalyst Community