Skip to content

Files

Latest commit

 

History

History

NodeJs

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Node.js

An Introduction to Node.js

azure

By me, Kyle Mitofsky, a developer


NodeJS

... an asynchronous, event-driven, JavaScript runtime, designed to build scalable network applications


Write an App

Language
&
Runtime

Client and Server

JavaScript Execution Environment


Functions 101

  • ECMAScript 20??
  • Callbacks
  • Promises
  • Async / Await

Function Declaration

// function declaration
function SayHi (name) {
    console.log(`Hi: ${name}`)
}

// function expression / assignment
let SayHey = function (name) {
    console.log(`Hey: ${name}`)
}

// arrow function / lambda
SayHello (name) => {
    console.log(`Hello: ${name}`)
}

Note: func delcarations -> are hoisted to the top of the scope (immediately available).
arrow func -> lecical this (defined by outer scope)

Functions Invocation

SayHi('kyle');

SayHi.Call(this, 'kyle');    // C for Comma

SayHi.Apply(this, ['kyle']); // A for Array

Return Result

function Multiply(a, b) {
    return a * b
}
// invoke

let result = Multiply(2,5)
console.log(result)

Callback w/ Result

function Multiply(a, b, callback) {
    callback(a * b) // pretend this took a while
}

// invoke w/ anonymous function
Multiply(2,5, (result) => {
    console.log(result)
})

Promises

// wrap a callback in a promise
function MultiplyPromise(a,b) {
    return new Promise((resolve) => {
        Multiply(a, b, (result) => {
            // resolve promise from in callback
            resolve(result)
        });
    });
}

Promise with Callback

let multPromise = MultiplyPromise(a,b)

multPromise.then(result => {
  console.log(result)
})

promise vizualizer

Promise with Async / Await

(async function(){

    let result = await MultiplyPromise(a,b)
    console.log(result)

})()

Node vs .NET

.NET Node
Language C# / VB / F# JS / TS
Runtime MSIL V8
Platform Win, Mac, Linux Win, Mac, Linux
Packages Nuget npm

Demo Time


Resources