Search this forum for the key words NodeJS, RPi, JavaScript, etc… there is a few snippets of code here and there that you might be able to extrapolate from…
I have posted some myself… If I have the time later to find some of them, will put the links here…