Learning Node.js basics in less than 22 hours
I just finished presenting Node.js after a 22 hour tech learning sprint. (Technically less than that since I did sleep).  It was fun to learn something new, yet rather difficult trying to cram everything into a 10 minute presentation, (and make sure the info you’re presenting is actually accurate...)    I’ll include the CliffsNotes version here! (random: look! CliffsNotes is now camelCase! :D)
On its website Node.js, defines itself as a “JavaScript runtime built on Chrome's V8 JavaScript engine.”  What this means is it’s javascript code on the server side running on a very fast engine. Â
It uses JavaScript.  JavaScript on the front-end, and Javascript in the backend.  What’s not to love?  no code potential conflicts?
Also, Node.js works asynchronously just like JavaScript in the browser, which means non-blocking processes run pretty much at the same time because it doesn’t wait for something to finish before starting another one. (It’s shuffled off the call stack to a worker that will trigger any callback functions). So that means…. you guessed it! It’s super fast! Â
One example of this is being to simultaneously read and write the same file at same time.  It’s not exactly the same time because one method is still started before another (as written in the order of your script), but more it doesn’t have to wait for a file to finish writing before starting to read/process it and vice versa.
Node.js is also event-driven!  If you’ve used JavaScript before, you’ve most likely fell in love with the event listeners that allow your users to interact with your webpage. It’s also here in Node.js but with different events attached, since you’re not working with the browser window object anymore.  There are even identically named methods, like setTimeout(), setInterval(), and .on().  Â
It’s highly scalable due to its asynchronous nature. The non-blocking characteristic allows it take a take on an enormous number of simultaneous connections with a high processing rate.
Scalable: same reason for big file I/O; you can do many things at the same time quickly (simultaneous connections to multiple clients)
Anything you want real-time : Node.js works really well for anything you want in real-time, such as chat apps. Â
Listening for events: its event loops checks for the events you’ve set listeners on and runs the attached callback methods. Â
Big File I/O:  Since it’s non-blocking, you can access the same file at the same time, start processing incoming data before it’s finished loading, etc.
CPU intensive processes pretty much negates its speediness.
Easy to end up in callback hell. Too many callbacks to keep track of...
Real-time Accurate Database dependent data: database processes are pretty much offloaded into callback methods, and the near instantaneous information you have now is not so instantaneous/accurate now until all the database methods have finished running.
A visit to the official Node.js site lists various methods to install Node (and npm). Â I installed with homebrew ($ brew install node) and it took less than a minute.
Sidenote: npm, short for node package manager, gives you access to the npm online repo of the many node modules.  It’s like what gems are for ruby.  It’s extremely useful for easy installation of modules and  automatically installs all the module’s dependencies. Just $ npm install _fabulousModuleName
To use the REPL/console for running js in terminal, just enter node and you can run javascript code here (like what irb is to ruby). Â To exit the console, type process.exit(0) or Ctrl-C twice. $ node someFile.js to run someFile.js
console.log in your JS file will output to your terminal (stdout)
Random interesting things about Node.js
In addition to boolean, number, string, and regex, there’s a new datatype called buffer.   Node.js docs describe Buffer as “[Raw data] stored in instances of the Buffer class. ... similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap.”  It’s basically a chunk of memory. Â
The Node.js Documentation is also color-coded for stability of a specific feature, which is interesting.  Although I’d like it even more if there were examples for all methods instead of just a few methods.
Everything in Node.js that has events are instances of the class event.EventEmitter .
There’s also this interesting thing call a stream, which is not a datatype.  It seems to correspond to a “stream” of data like files, input, and output.
Node.js code vs. javascript on the front-end Â
There are some differences: no access to the browser window object, since you’re on the backend, but syntax is still JS syntax. Â
One key difference I should mention is how to include your .js files into your code.  On the front-end, you include the link to your javascript file in your html code.  But there isn’t an html in the back-end!  In Node.js, any modules are required at the top of the file (using the CommonJS module pattern) like this: var http = require('http');
A Node.js web server is pretty easy to implement. I included the bare bones of one below that I bound to port 3005 of my computer and served my index.html file when I visited localhost:3005 in my browser. You can easily find many other different examples.
var http = require('http'); var fs = require('fs'); http.createServer(function(request, response){ //can(/should) include error handling with error status codes, etc. response.writeHead(200, {"Content-Type": "text/html"}); fs.readFile('index.html', function(error, contents){ if (error) console.log(error); // something to see errors // can write multiple globs of data with a bunch of response.write() response.write(contents); response.end(); }); }).listen(3005);
Note: you technically can put the content of your response as an argument in response.end() without having to use response.write(), like: response.end(“This is a cool response!”)  Â
This is not a web framework though. Â So, you would have to hand roll one yourself or use one of the many wonderful frameworks built on Node.js, such as Meteor, which is already on my giant list of things to eventually check out.
I’m have to see how to include my browser JS file with my index.html file when serving with my Node webserver.  It seems to be overwriting it with my html file.  hmm… more learning and research!
My classmates’ topics ranged from D3 to React to Redis to Ionic.   Joseph even did a presentation on on socket.io, which is built on Node.js, and used made a basic chat app demo! Â
So many things to learn, so little time.  It’s more a lifelong journey, than a sprint.  Enjoy the journey!  (...with lots of level up opportunities!  Game on.)
TIP: When researching be aware of when the information you’re looking for was written.  The info might be outdated/deprecated/rendered obsolete with newer versions/fixes, or simple third-party add-ons.