Node JS SDK - Overview

Node JS SDk has all the necessary methods to access the Catalyst Components and services. It allows you to declare and define Catalyst components whose behavior are predefined. For example, each Catalyst component has its equivalent NodeJS object in SDK and API equivalents are called methods in NodeJS.

Including Catalyst SDK in your Project

If you choose install dependencies option in the CLI while initializing the catalyst project, the node.js SDK will automatically be included in the generated sample boilerplate code. However, you can include it in your project, by executing the following command from the CATALYST_PROJECT_HOME directory in the CLI.

Copiednpm install --save zcatalyst-sdk-node

Initialize the SDK

The catalyst node.js must be initialized which would return an object. You can access the catalyst components of the current project thrugh this returned object. The different initialization methods for different type of functions are as given below,

SDK Initialization in Advanced I/O Functions with the Basic Template

Copiedvar catalyst = require('zcatalyst-sdk-node');
module.exports = (req, res) => {	
    var app = catalyst.initialize(req); 
//This app variable is used to access the catalyst components.
//You can refer the SDK docs for code samples.
//Your business logic comes here
}

SDK Initialization in Advanced I/O Functions with Express.js

Copiedconst expressApp = express();
var catalyst = require('zcatalyst-sdk-node');
const express = require('express');
expressApp.get('/',(req,res)=>{
	var app = catalyst.initialize(req); 
//This app variable is used to access the catalyst components.
//You can refer the SDK docs for code samples.
//Your business logic comes here
});
module.exports=expressApp;

SDK Initialization in BasicIO Functions

Copiedconst catalyst = require('zcatalyst-sdk-node');
module.exports = (context, basicIO) => {
const app = catalyst.initialize(context);
//This app variable is used to access the catalyst components.
//You can refer the SDK docs for code samples.
//Your business logic comes here
}

SDK Initialization in Event Functions

Copiedconst catalyst = require('zcatalyst-sdk-node');
module.exports = (event, context) => {
const app = catalyst.initialize(context);
//This app variable is used to access the catalyst components.
//You can refer the SDK docs for code samples.
//Your business logic comes here
}

SDK Intialization in Cron Functions

Copiedconst catalyst = require('zcatalyst-sdk-node');
module.exports = (cronDetails, context) => {
const app = catalyst.initialize(context);
//This app variable is used to access the catalyst components.
//You can refer the SDK docs for code samples.
//Your business logic comes here
}

Now you can access the components using the initialized variable.