You don't need any code on mdb42q at all to do this. You also don't need to 'wait' on MDBT42 side for anything.
You just need to connect from the pi to the MDBT42 and send JS code to set the GPIO as shown in example https://www.espruino.com/Web+Bluetooth that is the easiest way to do this. There are other ways with custom service on MDBT42 - see e.g. this https://www.espruino.com/BLE+Communications but this is more complicated. Since you are struggling even with the basics there is no point in doing that as step 1.
As I see it, the biggest issue for you is how to write code on Pi side to connect and send string like 'LED1.set();\n' to Nordic UART service on MDBT42 (or any custom service if you go for the more complicated solution) . In both cases the Pi side will be similar - connect, write data to some characteristics. If you want reply back then also subscribe to notifications and get output back.
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.
You don't need any code on mdb42q at all to do this. You also don't need to 'wait' on MDBT42 side for anything.
You just need to connect from the pi to the MDBT42 and send JS code to set the GPIO as shown in example https://www.espruino.com/Web+Bluetooth that is the easiest way to do this. There are other ways with custom service on MDBT42 - see e.g. this https://www.espruino.com/BLE+Communications but this is more complicated. Since you are struggling even with the basics there is no point in doing that as step 1.
As I see it, the biggest issue for you is how to write code on Pi side to connect and send string like
'LED1.set();\n'
to Nordic UART service on MDBT42 (or any custom service if you go for the more complicated solution) . In both cases the Pi side will be similar - connect, write data to some characteristics. If you want reply back then also subscribe to notifications and get output back.As for refusing connection from unknown devices check https://www.espruino.com/BLE+Security but I wouldn't worry about that in step 1.
Yes, there seems to be a lot of misunderstanding on your side in both how BLE works and also what you exactly want to do and how :-)
And BTW here is example of getting battery via (already suggested) espruino cli command
http://forum.espruino.com/conversations/297357/#13369180