How to integrate Node JS SDK in Bubble Application

Hi All,

I have following requirement, which after reading through forum I am unable to reach a good solution for. Would appreciate help and guidance in this matter.

I want to integrate a payment gateway (CCAvenue) in my application. The payment gateway has given NodeJS based SDK. The SDK has some Node JS files that handle some POST operations, some encryption of data etc.

I am trying to understand how do I incorporate this SDK in my application.

I have uploaded the files in SDK in my root directory.

I have tried these so far:

  1. Running those Node JS files via <script> in html elements and via client side Run Javascript of Toolbox plugin. This one fails because JS files have some require statements that use some modules. And apparently Bubble does not allow these in frontend (or maybe they are not supposed to run in frontend in NodeJS)

  2. Running these node JS files via Server Script of Toolbox plugin. This one fails because either require is not supported in these or because I am unable to figure out how do I use require and give reference to modules that I have uploaded to my root directory.

  3. Creating plugin to include NodeJS modules. I am unable to figure out how do I use require and give reference to modules that I have uploaded to my root directory.

Could someone please guide on what is the right method and how exactly do I go about it. If you could put it down in simple English terms than heavy tech words, it would be of great help.

Thanks,
Mukesh

A nodejs SDK is meant to run on the server.
You should create a plugin with a server side action. Specify the sdk as dependency in the package.json section of the editor and then require the package in your action code.
Installing the SDK as a dependency has nothing to do with uploading files in the root directory. Bubble will fetch the dependency from the registry and bundle it with your action code.
Since you mention encryption I suppose you have some sort of secret key. Be sure to store it as a private key in the global settings of the plugin so that it will be safely stored for server only use and it can be specified by the application using the plugin.

Thanks @dorilama for the reply.

How do I specify SDK as dependency in package.json? I think I am aware of how do I add a standard module as dependency in plugin (I read that just using require(modulename) will add the dependency in package.json automatically. Otherwise I can specify it in the dependencies section). However, the SDK that I have got was a zip file. When I unzipped it, it had a few .js files. I have uploaded those .js files to my root folder.

Some of those .js files are “request handler” type which expect some data coming to them via POST and some are exposed as modules and are used in other files via require For example one statement in one of the files is like this:

var http = require('http'),
    fs = require('fs'),
    ccav = require('./ccavutil.js'),
    qs = require('querystring');

And on this I get error that it can’t figure out how to get ./ccavutil.js. So I suppose I need a way to be able to access those modules in some different way. I am not aware of how do I do that.

Also, the ccavutil.js in itself has require('crypto') . I do not know if that will work as it is or do I need to do something special.

Also the handler file has code written such that it assumes it has got some parameters in POST request. Can that be put in Server Side Script in the plugin as it is?

Unfortunately bubble plugins are a bit limited. With local files you need to bundle everything in a big file that you paste in the action code before your own logic. It’s not ideal and can be tricky if you are not used to developing in js but it’s probably the quickest way to solve this.
An alternative is to publish the sdk as a public library. I don’t think that bubble can handle private registries or repositories, you may want to check that with support.
http, fs, querystring, crypto are modules provided with nodejs, you don’t need to do anything for that.

Thanks again.

Yes, that 's what I had started on a couple of hours ago as I was not able to find any solution. Still working on it though.

How do I do that? When I do that, will I be able to access module by just require(modulename)? or will I have to specify that in some path somewhere?

You would be better probably running this code elsewhere maybe on replit or another service.

Thanks @dorilama @mjohnson34 for your inputs. For now I have put the SDK in one file itself and that seems to be working. Though I am yet to try it out fully from different angles. But looks like it should work.

1 Like