Hi,
I’m trying to encode two auth strings to base64, I’m added the Crypto-js library using the package manager:

but I’m not able to call the right function, the console doesn’t show anything:

Library seems to be imported ok, but it doesn’t encode the strings, anybody have an idea why that’s not working?
Thanks in advance.
Shan
2
Use the ’ nodejs-base64-encode ’ package ( https://github.com/praveenp30/nodejs-base64-encode#readme )
Backend:
//encodeString.jsw
import encode from "nodejs-base64-encode";
export function myFunction(string) {
var base64File = encode.encode(string, 'base64');
return base64File;
}
Page Code:
//Page Code
import {myFunction} from 'backend/encodeString.jsw';
$w.onReady(function () {
let string = 'YOUR_API_KEY';
myFunction(string)
.then( (response) => {
console.log(response); //your base64 encoded string
});
});
Working perfectly! Thanks for the quick help!!!
Hi, I am using the same code but an error occurs.
My code is this:
//page code
import {myFunction} from 'backend/encodeString.jsw';
$w.onReady(async function () {
let string = '50033027299715739fa316d303aa-2ae2c6f3-33b0afdd';
const newStr = myFunction(string)
console.log(newStr)
});
//backend encodeString.jsw
import encode from "nodejs-base64-encode";
export function myFunction(string) {
var base64File = encode.encode(string, 'base64');
return base64File;
}
Is there something I did wrong?