Monday, 16 September 2019

Integrate functionality (from html/js file) into node js app with templating engine

Hey I have a simple code that works as a standalone html file (only contains js and html). It contains a few buttons. If you press one button, it starts a timer.Now i wanted to take this functionality into an app with NodeJs because I wanted to make a standalone desktop app (with electron) for this as a fun project and to start the timer of the buttons on KeyboardKeyPress I needed the scope for the global key hook, so I found iohook for nodejs and got it to work.So at the moment I have two separate components that work:html buttons that start a timer, if clickedglobal key hook that detects if a key is pressedNow I face the challenge of combining these two. And I tried a lot and really don't know how to continue anymore.​Things I already tried / thought about:- require iohook inside the PUG template but that doesn't work because the scope of the template doesn't know the require function.- tried to pass ioHook to the template, but it always throws the error, that it is undefined.- maybe it's a routing problem? but i don't know how to route or how to start that or how to route from the js to the template file and because i have multiple buttons i think it would reset the timers and maybe i would have to make it modular but that sound wayyyy to complicated for this little app, and i would like to keep it simple!- maybe i don't even need a templating engine or pug was a wrong choice?- maybe nodejs is the wrong choice for this?!​I really liked the idea of using nodejs for this because I can use node js to make a desktop app and also it provides some learning experience, as the company I work for uses node too and I wanted to get more experience with it. And here I would have a really nice use case for a fun app, which should be kind easy to write... i thought.Any tips are appreciated. I really don't know how to continue at this point.

Submitted September 16, 2019 at 12:11PM by chebi39

No comments:

Post a Comment