How to use NodeJS in a CRM widget?
I created a widget in Zoho CRM which uses html to function. I used the CLI (using zet) to create the widget in my local environment. The issue is that I'm trying to execute a piece of code in NodeJS that adds a new item to an AWS S3 bucket but it doesn't seem possible to execute NodeJS code on a CRM widget. Here's the HTML code.
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="UTF-8">
- </head>
- <body>
- <form action="javascript:loadAPI(document.getElementById(myFile)">
- <label>Upload a file to AWS S3</label>
- <input type="file" id="myFile" name="filename">
- <input type="submit">
- </form>
- <script type="text/javascript" src="myFunction.js">
- </script>
- </body>
- </html>
At the moment, if I want to add a new item to an AWS S3 bucket, I can use the following NodeJS code.
- const AWS = require('aws-sdk');
- AWS.config.update({region: 'us-east-2'});
- s3 = new AWS.S3({apiVersion: '2006-03-01'});
- // call S3 to retrieve upload file to specified bucket
- const file = "file.txt";
- const uploadParams = {Bucket: "test-folder", Key: '', Body: ''};
- const fs = require('fs');
- const fileStream = fs.createReadStream(file);
- fileStream.on('error', function(err) {
- console.log('File Error', err);
- });
- uploadParams.Body = fileStream;
- const path = require('path');
- uploadParams.Key = path.basename(file);
- s3.upload (uploadParams, function (err, data) {
- if (err) {
- console.log("Error", err);
- } if (data) {
- console.log("Upload Success", data.Location);
- }
- });
The problem is that I can't run this code on the widget since it uses normal javascript. I'm wondering if there's a way that I could run this NodeJS code from my widget app.