connecting the opposite way does not help you in any way, you need example for the Pi which connects the other way, not this piece of JS code for MDBT42. Then you would just send piece of javascript to toggle GPIO. As a start you can use web page in Chromium on the PI as per https://www.espruino.com/Web+Bluetooth - this is the easiest thing and web bluetooth works on the Pi
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
connecting the opposite way does not help you in any way, you need example for the Pi which connects the other way, not this piece of JS code for MDBT42. Then you would just send piece of javascript to toggle GPIO. As a start you can use web page in Chromium on the PI as per https://www.espruino.com/Web+Bluetooth - this is the easiest thing and web bluetooth works on the Pi
otherwise bluetooth in linux is a mess, there are many ways, maybe search raspberry forum or check this https://elinux.org/RPi_Bluetooth_LE#Using_Bluetooth_LE_with_Python or node.js via https://github.com/noble/noble or dierctly via https://www.npmjs.com/package/espruino which is using noble