|Installing Node.js on Windows, Mac|
|Thanks to Ryan Dahl’s presentations and materials, I have been able to follow along and learn a little about Node.js. I hope to show you what I learn as I learn it.
The first step is get the latest version of Node installed.
|Using Node.js interactively|
|Bring up a command prompt. Bring up a command prompt.
Type in node start the interpreter.
Define a function. You can ignore the “undefined” message.
You can now call the function, passing in “212.”
Notice we get “100” as the answer, since 212 Fahrenheit is 100 Celsius.
|Write Node.js scripts and running them|
|You can request the process id very simply.
If you want A LOT of information, just type in “process.” It is a lot of information.
This will list a lot details about the process, including environment variables.
Running Node.js Scripts
Simply type in “node [node.js code file]”
c:\> node simpleServer.js
|A simple HTTP Server – Demo|
|The code below creates a very basic web server.
The code below does the following:
|A Node.js TCP Server|
|We just demonstrated http. The next section is learning about TCP. TCP is considered a very lightweight protocol, free of the overhead of http. Notice in the code below we require ‘net,’ not ‘http.’ Everything else should look somewhat familiar from before.
But let’s be clear. TCP is a transport layer protocol and HTTP is an application layer protocol. HTTP (usually) operates over TCP, so whichever option you choose, it will still be operating over TCP.
TCP sockets are more bandwidth efficient, since HTTP contains a whole bunch of extra data (the headers) that would likely not be needed. HTTP is not particularly suited to n-way chat servers.
Download for Azure SDK