Node - tdkehoe/blog GitHub Wiki
#Why Node?
The Apache server was made in the era when the World Wide Web consisted of big events, e.g., getting a web page or posting a completed form. The web has become more, smaller pieces, with more, smaller events, e.g., after the user enters a zip code the form autofills in the state and city. AJAX was made to solve this problem. A Node server can feel faster as a webpage responds to many small user events.
Another is eval(). This command translates data in and out of JSON objects, especially when the client and server speak different langauges, e.g., JavaScript in the browser and PHP in the server. As data become complex eval() has translation and security problems. (JSON.parse() is better.)
##Why Not Use Node? Node may not be the best for heavy database and webpage rendering, e.g., WordPress.
#Install Node.js
Go to nodejs.org and follow the instructions.
##Check Your Version of Node
node -v
##Update Node
brew update
brew upgrade node
npm install -g npm
#How To Make a Node Server
A Node server has four parts:
- Interactions, defined as variables and included with
require. - Create a server with
createServer, attached as a method to thehttpinteraction. - Functions for handling requests.
- Specify a port with
listen.
require various things you need and define them as variables.