@rob_rich
#nodejs
by Rob Richardson
August 29, 2013
Rob Richardson is principal of Richardson & Sons, LLC, builder of ASP.NET and Node solutions for small- to medium-sized businesses. Rob has a BFA and MSCIS, and has been building software in .NET and HTML for over a dozen years, and frequently enjoys sharing his passion for software development at user groups and community events. Follow Rob at @rob_rich or on his blog at http://robrich.org/.
JavaScript runtime
Powered by Google V8
(the JavaScript engine in Chrome)
Runs on Windows and *nix
Very scalable webserver
Command-line tools
Very, very fast for I/O bound tasks
Single language for both browser and server-side
Everything is asynchronous, no blocking
Standard JavaScript
No global scope
Community of open-source packages
Goto http://nodejs.org/
Click Install
Push Next
Open Command Prompt / Terminal
node --version
node
read-eval-print loop
node app.js
There is no Thread.Sleep()
There is setTimeout(..)
Everything takes in a callback to return results
Event loop is free to handle other requests
callTheLib('pass','parameters', function (err, results) {
if (err) {
throw err; // Bad things happened
}
// It worked
});
Source: http://nodejs.org/
var http = require('http');
var port = process.env.PORT || 1337;
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(port);
console.log('Server running at http://127.0.0.1:'+port+'/');
Load modules into your code using CommonJS paradigm
(synchronous)
var lib_instance = require('lib_name');
Install package with NPM
(Node Package Manager)
npm install packagename
Load modules into your code
var lib_instance = require('packagename');
var http = require('http');
var port = process.env.PORT || 1337;
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(port);
console.log('Server running at http://127.0.0.1:'+port+'/');
Interesting, but not that useful
We prefer web frameworks
Enter Express: an MVC framework for Node
Source: http://expressjs.com/guide.html
npm install -g express
express myapp
cd myapp
npm install
node app.js
JSHint: detect errors in JavaScript code
Grunt: a JavaScript build tool
node-inspector: Uses Google Developer Tools to attach to Node's V8 engine.
WebStorm: an HTML5/CSS/JavaScript IDE by JetBrains
.NET | Node |
---|---|
Windows | Windows, *nix |
IIS | Node.exe |
ASP.NET | Node Core Modules |
ASP.NET MVC | Express (Like Sinatra) |
Razor | Jade |
NuGet | NPM (Installed with Node) |
SignalR | Socket.io |
Visual Studio |
WebStorm or Sublime Text or vi |
C# | JavaScript |