nginx -> Static html/javascript/images/css
node.js -> API
Apache -> old Python CGI stuff I still want (beautiful soup, for instance)
To me, this stack is a lot more comfortable, and is a lot faster.
----
Here are a couple of things that this tut misses.
1) You need to talk to your database. This will become immediately apparent when you try to do anything. You can google around, which will lead you to stack overflow, or you can just listen to me right here and use "mysql".
npm install mysql
Easy.2) Callbacks. This is freaking huge. node will not make any sense to you if you do not understand this. For instance, if you have a function called "get_username()" (Hi! I have a function called get username, I'm speaking from a mistake I made about this!), and you call it like this:
username = get_username();
res.write("Hi, you are: " + username);
res.end("buhbye!");
Your page is just going to crash because username is undefined. This is because node is nonblocking. It doesn't wait for get_username() to return before continuing...meaning your server will end before get_username() finishes.This is a problem.
So what you need to do won't make sense at first (and maybe I'm doing this wrong, correct me if I am).
you would do:
get_username(res);
and then you would have: function get_username(res) {
do_some_things;
db.query(query, function() { ;
//this is your db connectors callback function. It fires when your query is finished.
username = some_query_results['user'];
res.write("Hello, you are: " + username);
call_some_other_function();
or_if_this_is_the_last_thing_you_want_to_do_call res.end();
});
}
The point here [and this is obviously just pseudocode] is that you don't just write out a list of functions. You write functions that call each other when they're finished.read this: http://blog.mixu.net/2011/02/01/understanding-the-node-js-ev...