If you have experience with JavaScript, view your script as a JavaScript library and follow the same principles. Understand when the code is initially loaded and executed, and the exported functions are used by external code. Additionally, you can define a few functions for external events. These functions are called callbacks. They are invoked when an event occurs, such as a GPIO signal change or data being delivered via serial port.