Tuesday, 16 July 2019

Questions about deploying Node on servers

Apologies in advance if this is a long winded question, I'm trying to wrap my head around some new concepts.My background is in PHP, and I'm used to working with WHM/cPanel and WordPress. My flow has always been:HTTP request arrives at index.php in WordPress --> WordPress environment is created --> WordPress loads my code --> Response is sent to the client --> WordPress is dead until the next HTTP requestNode seems pretty different and I'm trying to figure out how this cycle works in Node. Specifically, does Node go "dead" until the next HTTP request?For example, to start up Node on my local machine, I type "node app.js" in my project directory and then Node is running. How does that happen on the server? Is it the HTTP request that triggers "node app.js" that then starts up my app, registers my routes, etc?Or...Does Node only start up once, and then I create a server with http.createServer() and it stays alive in the server memory triggering route callbacks until something turns off Node? This seems to be what the function names imply, but it leads me to a whole bunch of other questions like creating new routes as Node runs in the background, or how I would control this instance of Node or spawn others, and if there's administration panels for that sort of thing like WHM/cPanel. Also questions about best practices for writing code that is "running" in the background rather than just a response to a request (like with WordPress).I read this article already and while it answered pretty much all of my architecture questions, I'm still left wondering about how my app actually "runs" on a real server, and what point of my app is the "index.php" entry point.Here's one of my big questions; if Node only starts up once then lives the memory and triggers route callbacks, then do I have to worry about memory leaks in code that's outside of those callbacks, like a variable that never stops incrementing? These sorts of questions never came up in WordPress because with PHP it's all just 1 response to 1 request.Any advice on this is really appreciated, and feel free to share articles that go into detail on this. Thanks

Submitted July 17, 2019 at 12:57AM by abandonplanetearth

No comments:

Post a Comment