Slide 1

Slide 1 text

No content

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

No content

Slide 4

Slide 4 text

No content

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

No content

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

No content

Slide 11

Slide 11 text

No content

Slide 12

Slide 12 text

No content

Slide 13

Slide 13 text

No content

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

No content

Slide 17

Slide 17 text

Why Node.js? • Rapid innovation & delivery • Developer happiness • Attract & retain talent • Performance “Why Node.js is Becoming the Go-To Technology in the Enterprise” – nearform.com

Slide 18

Slide 18 text

Why Node.js? productivity satisfaction performance lower costs Improved results year-over-year Node.js Foundation User Survey

Slide 19

Slide 19 text

https://blog.platformatic.dev/nodejs-is-here-to-stay

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

No content

Slide 22

Slide 22 text

No content

Slide 23

Slide 23 text

• Backend API for SPAs, Mobile apps, etc. • “Serverless” computing • Real-time, streaming • WebSockets, push notifications • Chat, IM, social media Node.js Use Cases

Slide 24

Slide 24 text

More than just backend • Automation Scripts (DevOps) • CLI tools (compile with nexe) • Microservices • Internet of Things • Desktop Apps

Slide 25

Slide 25 text

Slack Visual Studio Code Figma

Slide 26

Slide 26 text

No content

Slide 27

Slide 27 text

DevOps • Small footprint • Cross-platform • Event-driven • OSS tools • Containers

Slide 28

Slide 28 text

No content

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

No content

Slide 35

Slide 35 text

Releases and Long-Term Support (LTS)

Slide 36

Slide 36 text

Node.js v22 • V8 12.4 • Maglev Compiler • Native watch mode • Native WebSocket • Mascot

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

Install Node.js https://nodejs.org

Slide 40

Slide 40 text

Install Node.js with NVM Mac or Linux? Use nvm! https://github.com/nvm-sh/nvm Windows? Install Windows Subsytem for Linux (WSL)! > nvm install 20

Slide 41

Slide 41 text

Install Node.js with NVM https://github.com/coreybutler/nvm-windows > nvm install 20

Slide 42

Slide 42 text

What You Get > node –v v20.16.0 > npm –v 10.8.2

Slide 43

Slide 43 text

> node –v v20.16.0 > npm –v 10.8.2 What You Get

Slide 44

Slide 44 text

First Things First! > mkdir myproject > cd myproject > npm init This utility will walk you through creating a package.json file!!...

Slide 45

Slide 45 text

Install Dependencies > npm install axios > npm install !--save-dev eslint > npm install -D eslint-config-reverentgeek

Slide 46

Slide 46 text

const fs = require( "fs" ); !// Built-in Node.js module const express = require( "express" ); !// Module installed via npm const ApiService = require( "./app/ApiService" ); !// Local module const api = new ApiService( { port: 8888 } ); module-examples.js

Slide 47

Slide 47 text

const fs = require( "fs" ); !// Built-in Node.js module const express = require( "express" ); !// Module installed via npm const ApiService = require( "./app/ApiService" ); !// Local module const api = new ApiService( { port: 8888 } ); module-examples.js

Slide 48

Slide 48 text

const fs = require( "fs" ); !// Built-in Node.js module const express = require( "express" ); !// Module installed via npm const ApiService = require( "./app/ApiService" ); !// Local module const api = new ApiService( { port: 8888 } ); module-examples.js

Slide 49

Slide 49 text

const fs = require( "fs" ); !// Built-in Node.js module const express = require( "express" ); !// Module installed via npm const ApiService = require( "./app/ApiService" ); !// Local module const api = new ApiService( { port: 8888 } ); module-examples.js

Slide 50

Slide 50 text

const fs = require( "fs" ); !// Built-in Node.js module const express = require( "express" ); !// Module installed via npm const ApiService = require( "./app/ApiService" ); !// Local module const api = new ApiService( { port: 8888 } ); module-examples.js

Slide 51

Slide 51 text

const ApiService = require( "./app/ApiService" ); const api = new ApiService( { port: 8888 } ); !// Traditional Node-style callback api.methodWithACallback( "bacon", 42, function( err, results ) { if ( err ) { !// Do something with the error console.log( err ); return; } !// Do stuff with results for ( let i = 0; i < results.length; i!++ ) { !// stuff!!... } } ); callback-example.js

Slide 52

Slide 52 text

const ApiService = require( "./app/ApiService" ); const api = new ApiService( { port: 8888 } ); !// Traditional Node-style callback api.methodWithACallback( "bacon", 42, function( err, results ) { if ( err ) { !// Do something with the error console.log( err ); return; } !// Do stuff with results for ( let i = 0; i < results.length; i!++ ) { !// stuff!!... } } ); callback-example.js

Slide 53

Slide 53 text

const ApiService = require( "./app/ApiService" ); const api = new ApiService( { port: 8888 } ); !// Traditional Node-style callback api.methodWithACallback( "bacon", 42, function( err, results ) { if ( err ) { !// Do something with the error console.log( err ); return; } !// Do stuff with results for ( let i = 0; i < results.length; i!++ ) { !// stuff!!... } } ); callback-example.js

Slide 54

Slide 54 text

const ApiService = require( "./app/ApiService" ); const api = new ApiService( { port: 8888 } ); !// Promise-style callback api.methodReturningAPromise( "bacon", 42 ) .then( results !=> { for ( let i = 0; i < results.length; i!++ ) { !// stuff!!... } } ) .catch( err !=> { console.log( err ); } ); promise-example.js

Slide 55

Slide 55 text

const ApiService = require( "./app/ApiService" ); const api = new ApiService( { port: 8888 } ); !// Promise-style callback api.methodReturningAPromise( "bacon", 42 ) .then( results !=> { for ( let i = 0; i < results.length; i!++ ) { !// stuff!!... } } ) .catch( err !=> { console.log( err ); } ); promise-example.js

Slide 56

Slide 56 text

const ApiService = require( "./app/ApiService" ); const api = new ApiService( { port: 8888 } ); !// Promise-style callback api.methodReturningAPromise( "bacon", 42 ) .then( results !=> { for ( let i = 0; i < results.length; i!++ ) { !// stuff!!... } } ) .catch( err !=> { console.log( err ); } ); promise-example.js

Slide 57

Slide 57 text

const ApiService = require( "./app/ApiService" ); const api = new ApiService( { port: 8888 } ); !// Promise-style callback api.methodReturningAPromise( "bacon", 42 ) .then( results !=> { for ( let i = 0; i < results.length; i!++ ) { !// stuff!!... } } ) .catch( err !=> { console.log( err ); } ); promise-example.js

Slide 58

Slide 58 text

const ApiService = require( "./app/ApiService" ); const api = new ApiService( { port: 8888 } ); !// Async-await callback async function doTheThing() { try { const users = await api.asyncMethodReturningUsers(); const results = await api.methodReturningAPromise( "bacon", 42 ); for ( let i = 0; i < results.length; i!++ ) { !// stuff!!... } } catch( err ) { console.log( err ); } } doTheThing(); async-await-example.js

Slide 59

Slide 59 text

const ApiService = require( "./app/ApiService" ); const api = new ApiService( { port: 8888 } ); !// Async-await callback async function doTheThing() { try { const users = await api.asyncMethodReturningUsers(); const results = await api.methodReturningAPromise( "bacon", 42 ); for ( let i = 0; i < results.length; i!++ ) { !// stuff!!... } } catch( err ) { console.log( err ); } } doTheThing(); async-await-example.js

Slide 60

Slide 60 text

const ApiService = require( "./app/ApiService" ); const api = new ApiService( { port: 8888 } ); !// Async-await callback async function doTheThing() { try { const users = await api.asyncMethodReturningUsers(); const results = await api.methodReturningAPromise( "bacon", 42 ); for ( let i = 0; i < results.length; i!++ ) { !// stuff!!... } } catch( err ) { console.log( err ); } } doTheThing(); async-await-example.js

Slide 61

Slide 61 text

const ApiService = require( "./app/ApiService" ); const api = new ApiService( { port: 8888 } ); !// Async-await callback async function doTheThing() { try { const users = await api.asyncMethodReturningUsers(); const results = await api.methodReturningAPromise( "bacon", 42 ); for ( let i = 0; i < results.length; i!++ ) { !// stuff!!... } } catch( err ) { console.log( err ); } } doTheThing(); async-await-example.js

Slide 62

Slide 62 text

function convertToCelsius( f ) { return ( f - 32 ) * ( 5 / 9 ); } function convertToFahrenheit( c ) { return ( c * ( 9 / 5 ) ) + 32; } const temp = { freezingCelsius: 0, freezingFahrenheit: 32, boilingCelsius: 100, boilingFahrenheit: 212, convertToCelsius, convertToFahrenheit }; module.exports = temp; temperature.js

Slide 63

Slide 63 text

function convertToCelsius( f ) { return ( f - 32 ) * ( 5 / 9 ); } function convertToFahrenheit( c ) { return ( c * ( 9 / 5 ) ) + 32; } const temp = { freezingCelsius: 0, freezingFahrenheit: 32, boilingCelsius: 100, boilingFahrenheit: 212, convertToCelsius, convertToFahrenheit }; module.exports = temp; temperature.js

Slide 64

Slide 64 text

function convertToCelsius( f ) { return ( f - 32 ) * ( 5 / 9 ); } function convertToFahrenheit( c ) { return ( c * ( 9 / 5 ) ) + 32; } const temp = { freezingCelsius: 0, freezingFahrenheit: 32, boilingCelsius: 100, boilingFahrenheit: 212, convertToCelsius, convertToFahrenheit }; module.exports = temp; temperature.js

Slide 65

Slide 65 text

function convertToCelsius( f ) { return ( f - 32 ) * ( 5 / 9 ); } function convertToFahrenheit( c ) { return ( c * ( 9 / 5 ) ) + 32; } const temp = { freezingCelsius: 0, freezingFahrenheit: 32, boilingCelsius: 100, boilingFahrenheit: 212, convertToCelsius, convertToFahrenheit }; module.exports = temp; temperature.js

Slide 66

Slide 66 text

function convertToCelsius( f ) { return ( f - 32 ) * ( 5 / 9 ); } function convertToFahrenheit( c ) { return ( c * ( 9 / 5 ) ) + 32; } const temp = { freezingCelsius: 0, freezingFahrenheit: 32, boilingCelsius: 100, boilingFahrenheit: 212, convertToCelsius, convertToFahrenheit }; module.exports = temp; temperature.js const t = require( "./temperature" ); const c = t.boilingCelsius; const f = t.convertToFahrenheit( c ); console.log( `${ c } C is ${ f } F` ); !// output: 100 C is 212 F temp-example.js

Slide 67

Slide 67 text

function convertToCelsius( f ) { return ( f - 32 ) * ( 5 / 9 ); } function convertToFahrenheit( c ) { return ( c * ( 9 / 5 ) ) + 32; } const temp = { freezingCelsius: 0, freezingFahrenheit: 32, boilingCelsius: 100, boilingFahrenheit: 212, convertToCelsius, convertToFahrenheit }; module.exports = temp; temperature.js const t = require( "./temperature" ); const c = t.boilingCelsius; const f = t.convertToFahrenheit( c ); console.log( `${ c } C is ${ f } F` ); !// output: 100 C is 212 F temp-example.js

Slide 68

Slide 68 text

function convertToCelsius( f ) { return ( f - 32 ) * ( 5 / 9 ); } function convertToFahrenheit( c ) { return ( c * ( 9 / 5 ) ) + 32; } const temp = { freezingCelsius: 0, freezingFahrenheit: 32, boilingCelsius: 100, boilingFahrenheit: 212, convertToCelsius, convertToFahrenheit }; module.exports = temp; temperature.js const t = require( "./temperature" ); const c = t.boilingCelsius; const f = t.convertToFahrenheit( c ); console.log( `${ c } C is ${ f } F` ); !// output: 100 C is 212 F temp-example.js

Slide 69

Slide 69 text

function convertToCelsius( f ) { return ( f - 32 ) * ( 5 / 9 ); } function convertToFahrenheit( c ) { return ( c * ( 9 / 5 ) ) + 32; } const temp = { freezingCelsius: 0, freezingFahrenheit: 32, boilingCelsius: 100, boilingFahrenheit: 212, convertToCelsius, convertToFahrenheit }; module.exports = temp; temperature.js const t = require( "./temperature" ); const c = t.boilingCelsius; const f = t.convertToFahrenheit( c ); console.log( `${ c } C is ${ f } F` ); !// output: 100 C is 212 F temp-example.js

Slide 70

Slide 70 text

function convertToCelsius( f ) { return ( f - 32 ) * ( 5 / 9 ); } function convertToFahrenheit( c ) { return ( c * ( 9 / 5 ) ) + 32; } const temp = { freezingCelsius: 0, freezingFahrenheit: 32, boilingCelsius: 100, boilingFahrenheit: 212, convertToCelsius, convertToFahrenheit }; module.exports = temp; temperature.js const t = require( "./temperature" ); const c = t.boilingCelsius; const f = t.convertToFahrenheit( c ); console.log( `${ c } C is ${ f } F` ); !// output: 100 C is 212 F temp-example.js

Slide 71

Slide 71 text

import { readFile } from "node:fs/promises"; export async function readFileJson( fileName ) { const text = await readFile( fileName ); const data = JSON.parse( text ); return data; } esm-module-example.js

Slide 72

Slide 72 text

import { readFile } from "node:fs/promises"; export async function readFileJson( fileName ) { const text = await readFile( fileName ); const data = JSON.parse( text ); return data; } esm-module-example.js

Slide 73

Slide 73 text

import { readFile } from "node:fs/promises"; export async function readFileJson( fileName ) { const text = await readFile( fileName ); const data = JSON.parse( text ); return data; } esm-module-example.js

Slide 74

Slide 74 text

esm-module-example.js import { readFile } from "node:fs/promises"; export async function readFileJson( fileName ) { const text = await readFile( fileName ); const data = JSON.parse( text ); return data; } esm-example.js import { readFileJson } from "./esm-module-example.mjs"; const baconFile = new URL( "./bacon.json", import.meta.url ); const bacon = await readFileJson( baconFile ); console.log( bacon );

Slide 75

Slide 75 text

esm-module-example.js import { readFile } from "node:fs/promises"; export async function readFileJson( fileName ) { const text = await readFile( fileName ); const data = JSON.parse( text ); return data; } esm-example.js import { readFileJson } from "./esm-module-example.mjs"; const baconFile = new URL( "./bacon.json", import.meta.url ); const bacon = await readFileJson( baconFile ); console.log( bacon );

Slide 76

Slide 76 text

const sql = require( "mssql" ); !// Read from environment variables const cnx = process.env.SQL_CONNECTION; async function getAccountByEmail( email ) { try { const pool = await sql.connect( cnx ); const result = await pool.request() .input( "email", sql.VarChar( 100 ), email ) .query( "select * from accounts where email = @email" ); return result; } catch ( err ) { !// log error } } sql-example.js

Slide 77

Slide 77 text

const sql = require( "mssql" ); !// Read from environment variables const cnx = process.env.SQL_CONNECTION; async function getAccountByEmail( email ) { try { const pool = await sql.connect( cnx ); const result = await pool.request() .input( "email", sql.VarChar( 100 ), email ) .query( "select * from accounts where email = @email" ); return result; } catch ( err ) { !// log error } } sql-example.js

Slide 78

Slide 78 text

const sql = require( "mssql" ); !// Read from environment variables const cnx = process.env.SQL_CONNECTION; async function getAccountByEmail( email ) { try { const pool = await sql.connect( cnx ); const result = await pool.request() .input( "email", sql.VarChar( 100 ), email ) .query( "select * from accounts where email = @email" ); return result; } catch ( err ) { !// log error } } sql-example.js

Slide 79

Slide 79 text

const sql = require( "mssql" ); !// Read from environment variables const cnx = process.env.SQL_CONNECTION; async function getAccountByEmail( email ) { try { const pool = await sql.connect( cnx ); const result = await pool.request() .input( "email", sql.VarChar( 100 ), email ) .query( "select * from accounts where email = @email" ); return result; } catch ( err ) { !// log error } } sql-example.js

Slide 80

Slide 80 text

const sql = require( "mssql" ); !// Read from environment variables const cnx = process.env.SQL_CONNECTION; async function getAccountByEmail( email ) { try { const pool = await sql.connect( cnx ); const result = await pool.request() .input( "email", sql.VarChar( 100 ), email ) .query( "select * from accounts where email = @email" ); return result; } catch ( err ) { !// log error } } sql-example.js

Slide 81

Slide 81 text

const sql = require( "mssql" ); !// Read from environment variables const cnx = process.env.SQL_CONNECTION; async function getAccountByEmail( email ) { try { const pool = await sql.connect( cnx ); const result = await pool.request() .input( "email", sql.VarChar( 100 ), email ) .query( "select * from accounts where email = @email" ); return result; } catch ( err ) { !// log error } } sql-example.js

Slide 82

Slide 82 text

const sql = require( "mssql" ); !// Read from environment variables const cnx = process.env.SQL_CONNECTION; async function getAccountByEmail( email ) { try { const pool = await sql.connect( cnx ); const result = await pool.request() .input( "email", sql.VarChar( 100 ), email ) .query( "select * from accounts where email = @email" ); return result; } catch ( err ) { !// log error } } sql-example.js

Slide 83

Slide 83 text

const sql = require( "mssql" ); !// Read from environment variables const cnx = process.env.SQL_CONNECTION; async function getAccountByEmail( email ) { try { const pool = await sql.connect( cnx ); const result = await pool.request() .input( "email", sql.VarChar( 100 ), email ) .query( "select * from accounts where email = @email" ); return result; } catch ( err ) { !// log error } } sql-example.js

Slide 84

Slide 84 text

const sql = require( "mssql" ); !// Read from environment variables const cnx = process.env.SQL_CONNECTION; async function getAccountByEmail( email ) { !!... } module.exports = { getAccountByEmail }; sql-example.js

Slide 85

Slide 85 text

No content

Slide 86

Slide 86 text

No content

Slide 87

Slide 87 text

No content

Slide 88

Slide 88 text

Developer tools Package(s) Description eslint lint and format rules for JavaScript nodemon automatically restarts in dev node:test, jest, mocha test frameworks testdouble, sinon spies, stubs, mocks

Slide 89

Slide 89 text

Recommended tools Package(s) Description dotenv loads environment variables from a .env file fs-extra adds convenient extensions to file system fetch, axios, or got http clients socket.io sockets, real-time commander command-line argument library for building CLIs nexe compile app to a standalone executable

Slide 90

Slide 90 text

Frameworks • Express.js • Fastify • Nest.js • Electron.js

Slide 91

Slide 91 text

Integration Strategies • Node.js as proxy, use http client • nginx • Messaging (e.g. RabbitMQ, ZeroMQ Azure Service Bus)

Slide 92

Slide 92 text

No content

Slide 93

Slide 93 text

https://bit.ly/node-crash-course