Node for .NET and Java Developers

December 2015 JaxARCSIG

JaxNode

  • Node.js User Group
  • Meet the third Thursday of each month
  • jaxnode.com

A brief History

1995

Java

Javascript

2009

Why learn Node.js

  • Many features making way to C# and Java
  • Microsoft heavily invested in Node.js
  • Broad cloud support from Amazon, Azure and IBM
  • Client side tools built with or use Node.js
  • Solves the C10K problem
  • Take advantage of vast Module ecosystem
  • Single threaded and Asynchronous by default

Misconceptions about JS

  • JavaSript is browser only *
  • JavaScript is slow *
  • Node.js is interpreted *
  • Not Object Oriented *

* None of these assumptions is true

The Truth

  • Node.js runs on top of V8 and libuv
  • Your code runs inside of a run loop
  • Node.js is event driven
  • Use clustering API to scale out your apps
  • Each process only requires 20MB of RAM
  • Very easy to create Microservices

Types of Apps

  • Web Apps
  • Service Apps REST/JSON
  • MicroService Apps
  • Socket Apps
  • Command Line tools
  • Message Queue and Bus Apps

Module System

  • Units of functionality called Modules
  • npmjs.org hosts over 100000 modules
  • NPM command line tool to install
  • Two types, native and JS only
  • Native modules extend V8s C++ framework
  • Modules stored in 'node_modules' sub folder
  • Import modules using require() function

Package.json

  • Used for configuration and meta information
  • npm init will create package.json
  • dependencies and devDependencies stored in this file

npm init

npm install

npm install module

npm install module --save

npm test

npm start

Useful NPM commands

walkthrough creating pkg.json

will grab your dependencies

installs individual module

installs includes in your dependencies

runs your unit tests

starts and runs your app

var http = require('http');

var hostname = '127.0.0.1';
var port = 1337;

http.createServer(function (req, res)  {
  res.writeHead(200, { 'Content-Type': 'text/plain' });
  res.end('Hello World\n');
}).listen(port, hostname, function ()  {
  console.log(`Server running at http://${hostname}:${port}/`);
});

Node Gotchas 

  • Duct type language
  • If Type system important TypeScript or @Scrypt
  • == not the same as ===
  • Async, break work up in chunks
  • Be careful with floating point math

Popular Frameworks

  • Socket.IO
  • Express
  • Hapi.js
  • Sails MVC
  • Seneca MicroServices

Demo

Resources

  • nodejs.org
  • Node Weekly
  • jaxnode.com
  • nodeschool.io

Questions?

Contact Me

  • David Fekke at gmail dot com
  • Skype: davidfekke
  • Twitter: @davidfekke @jaxnode
  • www.jaxnode.com
  • www.meetup.com/Jax-Node-js-UG/