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

    • Introducing GenAI Features in Catalyst QuickML

      Hi everyone, Building machine learning models can often feel slow and complex, especially when teams wait for perfect certainty before testing their ideas. But in reality, faster progress comes from early experimentation—trying out models quickly, learning
    • Announcing Deprecation of Catalyst File Store, Event Listeners, and Cron

      We would like to announce that the following Catalyst features are now in their deprecation phase and will reach End Of Life (EOL) on 30 April, 2026- Catalyst File Store Catalyst Event Listeners Catalyst Cron New users who sign up for Catalyst from today
    • 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

      Catalyst Community