4 ms·
Node.js via CGI
- kennu 17y agoWtf... What's the point of using Node.js if you don't use it as an event based HTTP server.
- pufuwozu 17y agoGood question. I just want to point out that yes, node.js through CGI is a massive bastardisation. The main reason for it was that I (and possibly some other people) want to make websites using JavaScript and then just chuck it on some cheap shared server. The reason specifically for node.js is because it's arguably the most popular form of server-side JavaScript. Yes, CGI spawns a new process for each request but V8 (the node.js VM) is crazy-insane fast. I haven't done any tests but my intuition (which is quite probably wrong) tells me that the cost of forking V8 (lightweight) is probably not as bad having a Python process ready and serving from it. By the time my blog receives enough requests that having a persistant process is necessary, I would have moved on to caching. Caching is the answer for blogs. Running node.js via CGI for a complex web application is definitely not the final answer. I've made the libary very similar to the built-in event based HTTP server so the cost of switching when the application gets too big is very insignificant. Find, replace 'cgi' -> 'http', chuck on a virtual machine and go!