Node for Salesforce Developers

January 2017

Jacksonville Salesforce Developers

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

  • Finding way into more Salesforce tools
  • Makes Concurrency easy 
  • Microsoft heavily invested in Node.js
  • Broad cloud support from Amazon, Azure, IBM and Heroku
  • 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

Node used for

  • Web Frontend Development
  • Mobile Development Cordova, React-Native
  • Desktop Apps (Electron)
  • Backend Services (AWS, Heroku, Azure, IBM)
  • IoT Devices (Tessel 2, Galleo)
  • Microsevices and APIs

Types of Apps

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

Module System

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

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 Flow
  • == not the same as ===
  • Async, break work up in chunks
  • Be careful with floating point math

ES6/ES2015/ES2016+

  • JavaScript has many new language features
  • LTS versions of Node have most of these features
  • Babel and TypeScript transpilers allow almost all ES2016/17 features

Popular Frameworks

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

Salesforce Node Now

  • JSForce
  • Salesforce DX
  • Salesforce Mobile SDK
  • forcedroid and forceios create
  • salesforce-lightning-cli
  • Cordova and React-Native

Demo

Resources

  • nodejs.org
  • Node Weekly
  • jaxnode.com
  • nodeschool.io
  • jsforce.github.io
  • developer.salesforce.com

Questions?

Contact Me

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

Node for Salesforce Developers

By David Fekke

Node for Salesforce Developers

These slides are for a presentation for the January 2017 Salesforce meeting

  • 1,330