
CGI Using Node.js - drinchev
http://www.cgi-node.org/home
======
allendoerfer
We had this 21 years ago:
[http://en.wikipedia.org/wiki/Netscape_Enterprise_Server](http://en.wikipedia.org/wiki/Netscape_Enterprise_Server)

~~~
angersock
That was before async was discovered, an innovation by the Node development
team.

~~~
allendoerfer
Irony does not work well on the interweb, my friend.

To clear things up:

a) the Node team did not invent async programming

b) you kill the event loop, if you spawn it per request using CGI

------
mikegioia
This is a pretty cool project. Does anyone know if a copy of the node binary
is made for each request? My concern is that if it's ~10MB on every request
that could become problematic.

It looks from the code that it runs your JS through it's own virtual machine,
though. I can't imagine funnelling Javascript through Javascript through Node
being worth while.

------
chubot
Does it actually use a new node.js process for every request? I thought that
node was kinda slow to start up because of the JIT and so forth.

------
q3k
I hope this is a joke.

~~~
rkrzr
Ah, I'm glad to see I'm not the only one who thought this was a joke. I'll
repost this on April 1st, I think.

------
homulilly
Using '<?' for embedded code is generally a bad idea since it conflicts with
xml. PHP has had it disabled by default and not recommended for years.

------
steakejjs
This might be a good time to post the link to Facebook's XHP

[https://www.facebook.com/notes/facebook-engineering/xhp-a-
ne...](https://www.facebook.com/notes/facebook-engineering/xhp-a-new-way-to-
write-php/294003943919)

I've been using XHP at work and love the improvements it has made to the new
code we are writing.

Posting this might not seem relevant, but the examples of "replacing php with
javascript" show one of the ugliest parts of PHP, and that is when
presentation becomes super tangled with business logic.

XHP is really really nice for outputting the contents of an array into HTML
(for example..it has many other really nice uses), and it would be very cool
to see them do something like that.

~~~
o_____________o
> show one of the ugliest parts of PHP, and that is when presentation becomes
> super tangled with business logic

You seen jsx?

~~~
jed_watson
Have you heard Pete Hunt's angle on "Separation of Concerns" vs. "Separation
of Technologies"?

imo JSX doesn't fall into this trap, it just looks like it should.

His JSConf EU talk is worth a watch if you're interested:
[http://2013.jsconf.eu/speakers/pete-hunt-react-rethinking-
be...](http://2013.jsconf.eu/speakers/pete-hunt-react-rethinking-best-
practices.html) (slides: [http://www.slideshare.net/floydophone/react-
preso-v2](http://www.slideshare.net/floydophone/react-preso-v2))

------
rifung
I was under the impression Node.js could already be used to run back end code?
Could someone explain to me (who is new to the industry) the difference
between what this does and what Node.js already did?

~~~
0x62
This is designed to run without shell access, and without installing Node.js.
Users on shared hosting cannot normally install Node.js, so are restricted to
the usual LAMP stack, however this allows users to bypass this and process
everything with Node.js.

~~~
aikah
> This is designed to run without shell access, and without installing
> Node.js.

How can you run that without installing node itself? the godaddy tutorial
specifically says one needs to upload nodejs on the server.Whether you are
running apt-get install node or uploading it,you are still installing node on
the server

~~~
Demiurge
apt-get requires root and can set up an http service as part of the
installation. uploading it doesn't do that.

------
avita1
Is there a real use-case for this? IIS has run server-side JS for years, and
nobody's really using it.

~~~
pjmlp
Some developers seem to be unwilling to learn anything else other than
JavaScript.

~~~
fsniper
Atwood's Law: any application that can be written in JavaScript, will
eventually be written in JavaScript.

------
thomas4019
Anyone have any ideas on the performance impact of this vs a typical NodeJS
installation? I imagine there's a lot more overhead from starting up the
process each time. A pretty cool idea but seems like this loses the benefits
of NodeJS, speed and scalability.

~~~
o_____________o
Yes, but don't underestimate the value of penetration into cheaper hosts like
DreamHost and Godaddy. PHP has always had quality issues, but survives on its
eternal ubiquity, which is in no small part because of the CGI model.

~~~
Vendan
Um, I would say it's mostly cause of mod_php support in apache, not cgi mode.
Also, the fact that 5 minutes gets you AMP installed on just about any OS.

On the topic of this site though, 3 exclamation marks on the title? Really???

------
fsniper
Strange, 22 year old technology is resurrected for javascript? cgi is an
expensive technology because it execs full application on every request. It
would be a bit more sane if it was implemented with fast-cgi.

Sometimes, I wish people did not hack for the sake of hacking.

------
syskaw
This is wrong way. Keep Node.js where it has to be

~~~
o_____________o
Diversity is a good thing.

~~~
louischatriot
Using 90s technologies with node is not really diversity, it's punishing
yourself on purpose ...

~~~
o_____________o
I agree with you and have the skill and facilities to run a VM with node as
most of the HN audience does, but this doesnt represent the majority of little
nobody sites that litter the web.

------
Animats
This looks useful. HostGator will host a web site for $3.96 a month. You can't
have any long-running processes. You're limited to CGI, PHP, and static pages.
For low-traffic web sites that need some modest amount of host-side
processing, that's an effective solution. There's nothing wrong with running a
Javascript engine instead of the usual Perl or Python engines under CGI.

If your e-commerce site does one sale a minute, you don't need Docker
containers running on AWS instances behind a content delivery network.

~~~
jed_watson
I'm not familiar with the benefits of HostGator but how is this better than
spinning up a free Heroku dyno to serve your node.js app?

That's also a very effective solution for low-traffic sites with a modest
amount of host-side processing and more than enough for one sale a minute.

It's got great options for 3rd-party service integration too (e.g. free
MongoDB hosting for < 512mb with MongoLab), and a very node.js friendly
environment / deployment workflow.

Not trolling, genuinely curious what the benefit of this would be as an
alternative.

~~~
Animats
_How is this better than spinning up a free Heroku dyno to serve your node.js
app?_

Heroku's free service is more limited than it was in 2012. Current policy:
"Heroku comes with 750 free dyno hours for development use. Beyond that you
must pay for what you use."

~~~
EdwardMSmith
That's 750 per month (a nice round number to cover a 31 day month):

[https://devcenter.heroku.com/articles/usage-and-
billing#750-...](https://devcenter.heroku.com/articles/usage-and-
billing#750-free-dyno-hours-per-app)

------
Floens
I like this idea, especially for a replacement if you want a quick, single
file script online and don't want to use PHP.

Does anyone know if there is something similar to this but with FastCGI?

------
sysk
It's crazy how some people in this thread get so emotional and negative about
a new tool. If you don't like it, just don't use it. Yes, we know that CGI is
slow and that you don't like Javascript.

------
dpweb
Did a Node module a while back to include PHP scripts in a node environment.
[https://github.com/digplan/php-node](https://github.com/digplan/php-node)

------
deniska
I still prefer PyHP:
[http://www.ccraig.org/software/pyhp/manual/sample.html](http://www.ccraig.org/software/pyhp/manual/sample.html)

------
eatonphil
This might be a really bad question that is just as applicable to Node.js in
general, but doesn't this get confusing distinguishing between the server-side
and client-side aspects?

~~~
geon
Not really. Compared to using separate languages on the server and client, I
feel that using the same language makes it a bit easier because I don't need
to switch "mode" when jumping back and forth in the code. Like, when working
on iOS apps, I sometimes write `self` instead of `this`.

I have sometime seen the argument for Node of using the same code on client
and backend simultaneously, but in practice I haven't found any use for that.
The only big thing I can think of is form/model validation, but if you do
ajax, you can just as well do all that on the server anyway.

~~~
TheAceOfHearts
Isomorphic apps. I've been playing around with React+Flux, and it's perfect.
You can write your API in any language you want (even keeping it as part of
node if you wish!), but the client is React. This means you can re-use almost
exactly the same code for the frontend and backend. You get server-side
rendering that delegates to the client once it has loaded.

I recently re-wrote my blog
([https://blog.cesarandreu.com/](https://blog.cesarandreu.com/)) to take this
approach. Repo: [https://github.com/cesarandreu/trois-
blog](https://github.com/cesarandreu/trois-blog)

The client bootstrap code that's used on the server is in
client/middleware.js. Aside from that it reuses the exact same code.

------
thomasfoster96
PHP in JavaScript? Node.js itself is much more versatile and often easier than
PHP (in my experience anyway), so I can only assume this is so Node.js can be
used as a drop in replacement.

I think the only thing missing would be automaticly including PHP.js

------
evo_9
I much prefer meteors approach to all this.

------
friendzis
AddHandler bugs again?

------
cerrelio
I don't see why "replace PHP" is needed in the title other than linkbait. This
is just a CGI dealy for Node. Even the article says "It can run along side
PHP."

~~~
nailer
Agreed, headline is for marketing purposes, but it means that folk stuck with
an environment where they'd otherwise be forced to use PHP have a choice not
to use it.

~~~
CmonDev
Which marketing purposes, first thought that comes to mind is "from bad to
even worse"?

------
greggman
This doesn't seem to replace PHP whatsoever.

I thought PHP didn't run as CGI, shelling to a separate program with every
request. It runs, in nearly all installations, as a plugin, saving the
overhead of spawning a new program.

That's just one of the many reasons it did so well back it the day because it
allowed a server to handle far more requests than CGI based stuff.

~~~
Xorlev
PHP can run as CGI, original Apache deployments ended up being that way. Then
everyone switched to mod_php/fcgi deployments.

------
carsongross
Now you have function(amount){

console.log(amount + " problems.");

}

------
gasping
This is why Node.js is receiving an enormous backlash from the programming
community. People keep peddling it as a solution to all problems when in
reality it has very limited utility in all but a few use cases. Pushing this
thing over old CGI technology and adding a hideous spaghetti-code HTML
interleaving syntax is akin to shoving it further down the throats of the
masses who don't want or need Node.js. The best thing to do is leave Node.js
in its corner of the ecosystem and let people find it if they need it. Why are
we even talking about CGI? It's 2015. This does nothing good for the developer
ecosystem.

I've got a running theory for the next 10 or so years of development.
Node.js's sole purpose was to lower the barrier to entry of server-side
development. With the barrier to entry lowered, inexperienced developers with
no knowledge of proper tooling are beginning to reinvent the wheel and make
the same mistakes we did 10 or fifteen years ago. We're going to see a tragic
repeat of the worst decisions made over the past few decades only this time
they'll be running on what is arguably one of the most poorly designed
programming languages, Javascript. Those who are too inexperienced to
understand history are doomed to repeat it.

~~~
emilsedgh
_Node.js 's sole purpose was to lower the barrier to entry of server-side
development._

async nature of nodejs, prototype based OO, callback hells and scope chain
make JS harder than Ruby and Python, IMHO.

I dont think nodejs lowers the barrier. Or am I mistaken?

~~~
gasping
You're quite right. Node.js is more like a trap for inexperienced developers
who probably won't even understand why Node.js is an awful tool when used to
solve the wrong problem because they have no real experience (I believe
Node.js is the wrong answer to the wrong problem in all but a very few
exceptional circumstances).

