SlideShare a Scribd company logo
Getting Started with Node.js
JUSTIN REOCK | CHIEF ARCHITECT | OPENLOGIC BY PERFORCE
Who is this nerd?
3 perforce.com
Justin Reock
Chief Architect
OpenLogic by Perforce
Presenter
Justin has over 20 years’ experience
working in various software roles and is
an outspoken free software evangelist,
delivering enterprise solutions and
community education on databases,
integration work, architecture, and
technical leadership.
He is currently the Chief Architect at
OpenLogic by Perforce.
4 perforce.com
GitHub Repo for
Demos
• https://github.com/jreock/
getting-started-with-
node.js
• ColorsModule will require
an “npm install” – but
don’t worry I’ll teach you
how to do it!
5 perforce.com
What are we going to solve?
7 perforce.com
8 perforce.com
Asychronous Processing
• No one likes the spinning wheel of doom hope!
• Node.js is inherently asynchronous, blocking actions only when it
absolutely needs to
• This is ideal for our new(ish) world of parallel compute,
distributed compute, microservices, etc…
• Built on industry standards and vetted against thousands of
production systems
What else?
10 perforce.com
A Long Time Ago…
Backend
Silo
Front End
Silo
Backend
Servers
Front End
Servers
App
11 perforce.com
Behold, The Future!
DevOps Team
App Farm
App
Node allows us to code our front end and our backend using a single language
12 perforce.com
Node.js Overview
• Created by Ryan Dahl in 2009 to address concurrency issues.
• Dahl famously “built it over the weekend…”
• Built on Chrome’s V8 JavaScript engine.
• Single-threaded asynchronous event driven JavaScript framework. In-
progress tasks can easily be checked for completion.
• Vertical scaling can be achieved by adding CPU cores and adding a worker to
each core. This means resources can be shared (via the cluster module and
child_process.fork(…)).
• Using JavaScript on the browser as well as the server minimizes the
mismatch between the environments. Example: Form validation code does
not have to be duplicated on both client and server.
• Node.js objects maintain a list of registered subscribers and notifies them
when their state changes (‘Observer’ design pattern).
13 perforce.com
Why reinvent the wheel?
• npm is the node (sic) package manager for Node.js.
• npm enables JavaScript developers to share code to
solve common problems promoting reuse. This
allows developers to take advantage of the expertise
of a large community.
• Very active and vibrant community: As of February
2017, there were nearly 400,000 total packages on
npm.
14 perforce.com
• NPM is the fastest growing
and most prolific module
repository out there
• Over a million modules and
growing
Source: www.modulecounts.com – August 2019
15 perforce.com
Benefits of Node.js
Pros
• Lightweight: Low memory footprint
• Cross-platform environment. Server and client-
side can be written in JavaScript.
• Fast: Asynchronous and event driven
• Popularity
• Concurrency implementation is abstract (handled
behind the scenes).
• Full Stack Web Development: Front-end
developers can code on the backend.
• Extensibility
Cons
• 1.7 GB memory limit (64-bit)
• Vertical scaling challenge (but workarounds exist)
• Module versions can get confusing
• Open source governance is not flawless (See
LeftPad)
• Learning curve for developers not used to dealing
with an inherently asynchronous language
16 perforce.com
Node.js Web-Enabled Hello World
var http = require('http');
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type':
'text/html'});
response.end('Hello World');
}).listen(8081);
http://www.haneycodes.net/to-node-js-or-not-to-node-js/
17 perforce.com
Node Architecture
18 perforce.com
Node’s Asynchronous Event Loop
19 perforce.com
Installing Node
• This will vary by environment, but Node can
be installed in several different ways:
• Linux Package Manager (like yum, apt-get,
pkg, emerge)
• Standalone installer
(https://nodejs.org/en/download/)
• Official Docker Image
• Standalone Shell Script
20 perforce.com
Verifying Node Install
• Once Node has been installed in your
environment, check to make sure NPM has been
installed as well
• You can validate the installation by simply
checking the version of each binary from the
command line:
21 perforce.com
Demo: A Quick Node App
• Node applications can be run using the “node”
command line binary
• We’ll write a simple console hello world app
from scratch
• We’ll then execute it on the command line
22 perforce.com
Picking an IDE
• I’ll cut to the chase, I really like
VSCode for Node.js development
• Terminal integration is essential
when building your Node apps
• And the built-in debugger works
flawlessly with Node.js
• However, you have other options
• In the end, go with what is familiar
and available (and is not Notepad)
23 perforce.com
Picking an IDE
• We’ve all got our preferences, but make sure whatever
you choose meets at least the following requirements:
üApplication Debugger
üSyntax Highlighting
üESLint
üTerminal Integration
üNPM Integration
üIntelliSense (Code Completion)
üCode Beautifier
üDocker Integration
üNode_modules Integration
üSource Control Integration
24 perforce.com
• Cloud 9: https://c9.io/
• Online Code Editor
• Debugging
• Docker Integration: https://github.com/kdelfour/cloud9-docker
• Live Preview
• JetBrains WebStorm: https://www.jetbrains.com/webstorm/
• Code Completion
• Debugger
• Komodo IDE: http://www.activestate.com/komodo-ide
• Nodeclipse: http://www.nodeclipse.org/
• Eclipse with Node.js Plugins
25 perforce.com
Setting up VSCode
• Countless VSCode extensions exist
• Start With at least:
• Node Debug
• Node.js Extension Pack
• Take time to explore what is out there
26 perforce.com
Understanding Launch.json in VSCode
• In VSCode, application launch configuration is
controlled through a JSON file called “launch.json”
• This file will be referenced before VSCode launches
the app when debugging
• It describes the environment the application will
run in including environment variables, bootstrap
information, etc
• It is essential for debugging, and convenient for
launching unit and functional tests
27 perforce.com
Demo: Debugging an App in VSCode
• We’ll modify our HelloWorld example to store
our message in a variable
• Then we’ll create a launch configuration for our
project
• Finally, we’ll launch our project and inspect our
message variable
28 perforce.com
Node App Basic Lifecycle
• If you are using SCM
• Don’t forget relevant
‘ignore’ files
Create and Clone
SCM Repo*
• Run "npm init" in
new project folder
Initialize Project
• Get to it!
• If using SCM, commit
as normal!
Code!
• In target production
environment, run
"npm install" to
download necessary
dependencies
Build
* Just create new folder if
not using SCM
29 perforce.com
Node App Basic Lifecycle
* Just create new folder if
not using SCM
• If you are using SCM
• Don’t forget relevant
‘ignore’ files
Create and Clone
SCM Repo*
• Run "npm init" in
new project folder
Initialize Project
• Get to it!
• If using SCM, commit
as normal!
Code!
• In target production
environment, run
"npm install" to
download necessary
dependencies
Build
30 perforce.com
Initializing a Node App
• It’s development best practice to use npm to initialize a new
Node.js app
• This process will prompt the user for several standard pieces of
metainformation about the application
• Things like the application name, version, license, and bootstrap
class will be collected
• NPM will generate a build configuration file for the app called
package.json
• Package.json will describe to NPM everything needed to build
your Node.js app
Demo: Initializing a Node app
• Let’s turn our HelloWorld demo into a proper
Node application
• We’ll run npm init in the root folder and
answer the prompts
• Then we’ll look at what NPM has done for us
32 perforce.com
Understanding package.json
• After running “npm
init”, this file will be
generated in the
project root folder
• Our project currently
has no
dependencies, but
dependency
information is held
here too
{
"name": "helloworld",
"version": "1.0.0",
"description": "Hello World!",
"main": "hello.js",
"scripts": {
"test": "echo "Error: no test
specified" && exit 1"
},
"author": "Justin Reock",
"license": "GPL-3.0-or-later"
}
33 perforce.com
Working with dependencies
• Our final topic will introduce dependencies, or modules
• Most modern open-source languages have a set of open-source
modules that can be added to a project
• You can also create your own modules, whether private or freely
available
• Recall that the NPM repository provides these modules
• NPM can also be used to add dependencies to a project, in both
development and production environments, using the “npm
install” command
• Once NPM has installed a module into a project, a developer can
begin using it with the “require” directive inside the Node.js app
34 perforce.com
Example: Let’s Add Some Color
• The “colors” module for Node adds easy support for generating
console colors through escape commands
• You want your console output to be readable, and even fun!
• The colors module makes that easy, and we can add it with npm
install
• Note that the –-save directive will ensure that the module is saved
to package.json
npm install –-save colors
var colors = require(‘colors’);
console.log(colors.red.underline(‘This is red underlined text.’);
or
console.log(‘This is red underlined text.’.underline.red)
35 perforce.com
Demo: Adding Project Modules from NPM
• So, let’s add some color to our HelloWorld app!
• We’ll use npm to install the “colors” module
and make sure it’s contained in package.json
• Then we’ll ”require” that module, and use it in
our code
• BONUS: Remove the node_modules and
rebuild with npm install
Conclusion and wrap-up
37 perforce.com
What did we learn?
• Node.js is a language that focuses on concurrency and unified
development
• Dependencies (modules) and builds are assisted through npm
• Node is asynchronous by default
• Many IDEs exist for Node.js, and we have focused on VSCode
• Node projects should be initialized using ”npm init”
• Modules can be installed with “npm install –save [module]”
• Projects are built from package.json in other environments with “npm
install”
• Modules are included as variables in a project using the “require”
directive
38 perforce.com
What Next?
• Node is a huge subject, but, I’d focus on the following from
here:
• Understand Asynchronous Coding
• Get to Know Events and Streams
• Learn about Functional Programming
• Master your IDE’s Debugger
• Start Exploring Other Modules!
• Still So Much to Learn!!
39 perforce.com
Feel free to reach out -- I get lonely!
LinkedIn – Only Justin Reock in the world
apparently!
Twitter – @jreock - But I do get a little
political on there….
Blog - https://www.openlogic.com/blog
Email – justin.reock@roguewave.com
Questions?
Ad

More Related Content

What's hot (20)

.NET Core in the Real World
.NET Core in the Real World.NET Core in the Real World
.NET Core in the Real World
Nate Barbettini
 
Eclipse OMR: a modern toolkit for building language runtimes
Eclipse OMR: a modern toolkit for building language runtimesEclipse OMR: a modern toolkit for building language runtimes
Eclipse OMR: a modern toolkit for building language runtimes
Mark Stoodley
 
Introduction to Containers and Docker for PHP developers
Introduction to Containers and Docker for PHP developersIntroduction to Containers and Docker for PHP developers
Introduction to Containers and Docker for PHP developers
Robert McFrazier
 
Symfony Day 2009 - Symfony vs Integrating products
Symfony Day 2009 - Symfony vs Integrating productsSymfony Day 2009 - Symfony vs Integrating products
Symfony Day 2009 - Symfony vs Integrating products
Xavier Lacot
 
Sutol 2016 - Automation is developer's friend
Sutol 2016 - Automation is developer's friendSutol 2016 - Automation is developer's friend
Sutol 2016 - Automation is developer's friend
mpradny
 
Os Koziarsky
Os KoziarskyOs Koziarsky
Os Koziarsky
oscon2007
 
Understanding Android Benchmarks
Understanding Android BenchmarksUnderstanding Android Benchmarks
Understanding Android Benchmarks
Koan-Sin Tan
 
Maven: from Scratch to Production (.pdf)
Maven: from Scratch to Production (.pdf)Maven: from Scratch to Production (.pdf)
Maven: from Scratch to Production (.pdf)
Johan Mynhardt
 
.NET Core Blimey! Windows Platform User Group, Manchester
.NET Core Blimey! Windows Platform User Group, Manchester.NET Core Blimey! Windows Platform User Group, Manchester
.NET Core Blimey! Windows Platform User Group, Manchester
citizenmatt
 
Dd13.2013.milano.open ntf
Dd13.2013.milano.open ntfDd13.2013.milano.open ntf
Dd13.2013.milano.open ntf
Ulrich Krause
 
.NET Core: a new .NET Platform
.NET Core: a new .NET Platform.NET Core: a new .NET Platform
.NET Core: a new .NET Platform
Alex Thissen
 
Zend con 2016 bdd with behat for beginners
Zend con 2016   bdd with behat for beginnersZend con 2016   bdd with behat for beginners
Zend con 2016 bdd with behat for beginners
Adam Englander
 
Highly Surmountable Challenges in Ruby+OMR JIT Compilation
Highly Surmountable Challenges in Ruby+OMR JIT CompilationHighly Surmountable Challenges in Ruby+OMR JIT Compilation
Highly Surmountable Challenges in Ruby+OMR JIT Compilation
Matthew Gaudet
 
C++ on the Web: Run your big 3D game in the browser
C++ on the Web: Run your big 3D game in the browserC++ on the Web: Run your big 3D game in the browser
C++ on the Web: Run your big 3D game in the browser
Andre Weissflog
 
Production Ready WordPress - WC Utrecht 2017
Production Ready WordPress  - WC Utrecht 2017Production Ready WordPress  - WC Utrecht 2017
Production Ready WordPress - WC Utrecht 2017
Edmund Turbin
 
Dr. Strangelove, or how I learned to love plugin development
Dr. Strangelove, or how I learned to love plugin developmentDr. Strangelove, or how I learned to love plugin development
Dr. Strangelove, or how I learned to love plugin development
Ulrich Krause
 
GraalVM - MadridJUG 2019-10-22
GraalVM - MadridJUG 2019-10-22GraalVM - MadridJUG 2019-10-22
GraalVM - MadridJUG 2019-10-22
Jorge Hidalgo
 
Workflow for Development, Release and Versioning with OSGi / bndtools- Real W...
Workflow for Development, Release and Versioning with OSGi / bndtools- Real W...Workflow for Development, Release and Versioning with OSGi / bndtools- Real W...
Workflow for Development, Release and Versioning with OSGi / bndtools- Real W...
mfrancis
 
Net core
Net coreNet core
Net core
Damir Dobric
 
Why Python In Entertainment Industry?
Why Python In Entertainment Industry?Why Python In Entertainment Industry?
Why Python In Entertainment Industry?
Shuen-Huei Guan
 
.NET Core in the Real World
.NET Core in the Real World.NET Core in the Real World
.NET Core in the Real World
Nate Barbettini
 
Eclipse OMR: a modern toolkit for building language runtimes
Eclipse OMR: a modern toolkit for building language runtimesEclipse OMR: a modern toolkit for building language runtimes
Eclipse OMR: a modern toolkit for building language runtimes
Mark Stoodley
 
Introduction to Containers and Docker for PHP developers
Introduction to Containers and Docker for PHP developersIntroduction to Containers and Docker for PHP developers
Introduction to Containers and Docker for PHP developers
Robert McFrazier
 
Symfony Day 2009 - Symfony vs Integrating products
Symfony Day 2009 - Symfony vs Integrating productsSymfony Day 2009 - Symfony vs Integrating products
Symfony Day 2009 - Symfony vs Integrating products
Xavier Lacot
 
Sutol 2016 - Automation is developer's friend
Sutol 2016 - Automation is developer's friendSutol 2016 - Automation is developer's friend
Sutol 2016 - Automation is developer's friend
mpradny
 
Os Koziarsky
Os KoziarskyOs Koziarsky
Os Koziarsky
oscon2007
 
Understanding Android Benchmarks
Understanding Android BenchmarksUnderstanding Android Benchmarks
Understanding Android Benchmarks
Koan-Sin Tan
 
Maven: from Scratch to Production (.pdf)
Maven: from Scratch to Production (.pdf)Maven: from Scratch to Production (.pdf)
Maven: from Scratch to Production (.pdf)
Johan Mynhardt
 
.NET Core Blimey! Windows Platform User Group, Manchester
.NET Core Blimey! Windows Platform User Group, Manchester.NET Core Blimey! Windows Platform User Group, Manchester
.NET Core Blimey! Windows Platform User Group, Manchester
citizenmatt
 
Dd13.2013.milano.open ntf
Dd13.2013.milano.open ntfDd13.2013.milano.open ntf
Dd13.2013.milano.open ntf
Ulrich Krause
 
.NET Core: a new .NET Platform
.NET Core: a new .NET Platform.NET Core: a new .NET Platform
.NET Core: a new .NET Platform
Alex Thissen
 
Zend con 2016 bdd with behat for beginners
Zend con 2016   bdd with behat for beginnersZend con 2016   bdd with behat for beginners
Zend con 2016 bdd with behat for beginners
Adam Englander
 
Highly Surmountable Challenges in Ruby+OMR JIT Compilation
Highly Surmountable Challenges in Ruby+OMR JIT CompilationHighly Surmountable Challenges in Ruby+OMR JIT Compilation
Highly Surmountable Challenges in Ruby+OMR JIT Compilation
Matthew Gaudet
 
C++ on the Web: Run your big 3D game in the browser
C++ on the Web: Run your big 3D game in the browserC++ on the Web: Run your big 3D game in the browser
C++ on the Web: Run your big 3D game in the browser
Andre Weissflog
 
Production Ready WordPress - WC Utrecht 2017
Production Ready WordPress  - WC Utrecht 2017Production Ready WordPress  - WC Utrecht 2017
Production Ready WordPress - WC Utrecht 2017
Edmund Turbin
 
Dr. Strangelove, or how I learned to love plugin development
Dr. Strangelove, or how I learned to love plugin developmentDr. Strangelove, or how I learned to love plugin development
Dr. Strangelove, or how I learned to love plugin development
Ulrich Krause
 
GraalVM - MadridJUG 2019-10-22
GraalVM - MadridJUG 2019-10-22GraalVM - MadridJUG 2019-10-22
GraalVM - MadridJUG 2019-10-22
Jorge Hidalgo
 
Workflow for Development, Release and Versioning with OSGi / bndtools- Real W...
Workflow for Development, Release and Versioning with OSGi / bndtools- Real W...Workflow for Development, Release and Versioning with OSGi / bndtools- Real W...
Workflow for Development, Release and Versioning with OSGi / bndtools- Real W...
mfrancis
 
Why Python In Entertainment Industry?
Why Python In Entertainment Industry?Why Python In Entertainment Industry?
Why Python In Entertainment Industry?
Shuen-Huei Guan
 

Similar to Getting Started with Node.js (20)

Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
Chris Cowan
 
Node.js
Node.jsNode.js
Node.js
krishnapriya Tadepalli
 
Building Open-source React Components
Building Open-source React ComponentsBuilding Open-source React Components
Building Open-source React Components
Zack Argyle
 
Building Open-Source React Components
Building Open-Source React ComponentsBuilding Open-Source React Components
Building Open-Source React Components
Zack Argyle
 
How to Install Node.js and NPM on Windows and Mac?
How to Install Node.js and NPM on Windows and Mac?How to Install Node.js and NPM on Windows and Mac?
How to Install Node.js and NPM on Windows and Mac?
Inexture Solutions
 
Steps to Install NPM and Node.js on Windows and MAC
Steps to Install NPM and Node.js on Windows and MACSteps to Install NPM and Node.js on Windows and MAC
Steps to Install NPM and Node.js on Windows and MAC
Inexture Solutions
 
3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't
F5 Buddy
 
ASP.NET 5 - Microsoft's Web development platform reimagined
ASP.NET 5 - Microsoft's Web development platform reimaginedASP.NET 5 - Microsoft's Web development platform reimagined
ASP.NET 5 - Microsoft's Web development platform reimagined
Alex Thissen
 
Android NDK
Android NDKAndroid NDK
Android NDK
Sentinel Solutions Ltd
 
Android ndk
Android ndkAndroid ndk
Android ndk
Sentinel Solutions Ltd
 
Deploy and Update Jakarta EE & MicroProfile applications with Paketo.pptx
Deploy and Update Jakarta EE & MicroProfile applications with Paketo.pptxDeploy and Update Jakarta EE & MicroProfile applications with Paketo.pptx
Deploy and Update Jakarta EE & MicroProfile applications with Paketo.pptx
Jamie Coleman
 
Node js meetup
Node js meetupNode js meetup
Node js meetup
Ansuman Roy
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll build
Mark Stoodley
 
Unikernel User Summit 2015: Getting started in unikernels using the rump kernel
Unikernel User Summit 2015: Getting started in unikernels using the rump kernelUnikernel User Summit 2015: Getting started in unikernels using the rump kernel
Unikernel User Summit 2015: Getting started in unikernels using the rump kernel
The Linux Foundation
 
Who Needs Visual Studio?
Who Needs Visual Studio?Who Needs Visual Studio?
Who Needs Visual Studio?
Christopher Gomez
 
Overview of Node JS
Overview of Node JSOverview of Node JS
Overview of Node JS
Jacob Nelson
 
Node Summit 2016: Building your DevOps for Node.js
Node Summit 2016: Building your DevOps for Node.jsNode Summit 2016: Building your DevOps for Node.js
Node Summit 2016: Building your DevOps for Node.js
Chetan Desai
 
Dynamic Languages in Production: Progress and Open Challenges
Dynamic Languages in Production: Progress and Open ChallengesDynamic Languages in Production: Progress and Open Challenges
Dynamic Languages in Production: Progress and Open Challenges
bcantrill
 
Modern Web-site Development Pipeline
Modern Web-site Development PipelineModern Web-site Development Pipeline
Modern Web-site Development Pipeline
GlobalLogic Ukraine
 
NCDevCon 2017 - Cross Platform Mobile Apps
NCDevCon 2017 - Cross Platform Mobile AppsNCDevCon 2017 - Cross Platform Mobile Apps
NCDevCon 2017 - Cross Platform Mobile Apps
John M. Wargo
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
Chris Cowan
 
Building Open-source React Components
Building Open-source React ComponentsBuilding Open-source React Components
Building Open-source React Components
Zack Argyle
 
Building Open-Source React Components
Building Open-Source React ComponentsBuilding Open-Source React Components
Building Open-Source React Components
Zack Argyle
 
How to Install Node.js and NPM on Windows and Mac?
How to Install Node.js and NPM on Windows and Mac?How to Install Node.js and NPM on Windows and Mac?
How to Install Node.js and NPM on Windows and Mac?
Inexture Solutions
 
Steps to Install NPM and Node.js on Windows and MAC
Steps to Install NPM and Node.js on Windows and MACSteps to Install NPM and Node.js on Windows and MAC
Steps to Install NPM and Node.js on Windows and MAC
Inexture Solutions
 
3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't3 Things Everyone Knows About Node JS That You Don't
3 Things Everyone Knows About Node JS That You Don't
F5 Buddy
 
ASP.NET 5 - Microsoft's Web development platform reimagined
ASP.NET 5 - Microsoft's Web development platform reimaginedASP.NET 5 - Microsoft's Web development platform reimagined
ASP.NET 5 - Microsoft's Web development platform reimagined
Alex Thissen
 
Deploy and Update Jakarta EE & MicroProfile applications with Paketo.pptx
Deploy and Update Jakarta EE & MicroProfile applications with Paketo.pptxDeploy and Update Jakarta EE & MicroProfile applications with Paketo.pptx
Deploy and Update Jakarta EE & MicroProfile applications with Paketo.pptx
Jamie Coleman
 
Oh the compilers you'll build
Oh the compilers you'll buildOh the compilers you'll build
Oh the compilers you'll build
Mark Stoodley
 
Unikernel User Summit 2015: Getting started in unikernels using the rump kernel
Unikernel User Summit 2015: Getting started in unikernels using the rump kernelUnikernel User Summit 2015: Getting started in unikernels using the rump kernel
Unikernel User Summit 2015: Getting started in unikernels using the rump kernel
The Linux Foundation
 
Overview of Node JS
Overview of Node JSOverview of Node JS
Overview of Node JS
Jacob Nelson
 
Node Summit 2016: Building your DevOps for Node.js
Node Summit 2016: Building your DevOps for Node.jsNode Summit 2016: Building your DevOps for Node.js
Node Summit 2016: Building your DevOps for Node.js
Chetan Desai
 
Dynamic Languages in Production: Progress and Open Challenges
Dynamic Languages in Production: Progress and Open ChallengesDynamic Languages in Production: Progress and Open Challenges
Dynamic Languages in Production: Progress and Open Challenges
bcantrill
 
Modern Web-site Development Pipeline
Modern Web-site Development PipelineModern Web-site Development Pipeline
Modern Web-site Development Pipeline
GlobalLogic Ukraine
 
NCDevCon 2017 - Cross Platform Mobile Apps
NCDevCon 2017 - Cross Platform Mobile AppsNCDevCon 2017 - Cross Platform Mobile Apps
NCDevCon 2017 - Cross Platform Mobile Apps
John M. Wargo
 
Ad

More from Justin Reock (14)

DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
DORA Community - Building 10x Development Organizations.pdf
DORA Community - Building 10x Development Organizations.pdfDORA Community - Building 10x Development Organizations.pdf
DORA Community - Building 10x Development Organizations.pdf
Justin Reock
 
DevOpsDays LA - Platform Engineers are Product Managers.pdf
DevOpsDays LA - Platform Engineers are Product Managers.pdfDevOpsDays LA - Platform Engineers are Product Managers.pdf
DevOpsDays LA - Platform Engineers are Product Managers.pdf
Justin Reock
 
DevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdfDevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdf
Justin Reock
 
Building 10x Development Organizations.pdf
Building 10x Development Organizations.pdfBuilding 10x Development Organizations.pdf
Building 10x Development Organizations.pdf
Justin Reock
 
Open Source AI and ML, Whats Possible Today?
Open Source AI and ML, Whats Possible Today?Open Source AI and ML, Whats Possible Today?
Open Source AI and ML, Whats Possible Today?
Justin Reock
 
Community vs. Commercial Open Source
Community vs. Commercial Open SourceCommunity vs. Commercial Open Source
Community vs. Commercial Open Source
Justin Reock
 
Monitoring Java Applications with Prometheus and Grafana
Monitoring Java Applications with Prometheus and GrafanaMonitoring Java Applications with Prometheus and Grafana
Monitoring Java Applications with Prometheus and Grafana
Justin Reock
 
Intro to React
Intro to ReactIntro to React
Intro to React
Justin Reock
 
Integrating Postgres with ActiveMQ and Camel
Integrating Postgres with ActiveMQ and CamelIntegrating Postgres with ActiveMQ and Camel
Integrating Postgres with ActiveMQ and Camel
Justin Reock
 
Node.js Deeper Dive
Node.js Deeper DiveNode.js Deeper Dive
Node.js Deeper Dive
Justin Reock
 
Linux 101
Linux 101Linux 101
Linux 101
Justin Reock
 
ZendCon - Integration and Asynchronous Processing with ActiveMQ and Camel
ZendCon - Integration and Asynchronous Processing with ActiveMQ and CamelZendCon - Integration and Asynchronous Processing with ActiveMQ and Camel
ZendCon - Integration and Asynchronous Processing with ActiveMQ and Camel
Justin Reock
 
ZendCon - Linux 101
ZendCon - Linux 101ZendCon - Linux 101
ZendCon - Linux 101
Justin Reock
 
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptxDevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
DevOpsDays Atlanta 2025 - Building 10x Development Organizations.pptx
Justin Reock
 
DORA Community - Building 10x Development Organizations.pdf
DORA Community - Building 10x Development Organizations.pdfDORA Community - Building 10x Development Organizations.pdf
DORA Community - Building 10x Development Organizations.pdf
Justin Reock
 
DevOpsDays LA - Platform Engineers are Product Managers.pdf
DevOpsDays LA - Platform Engineers are Product Managers.pdfDevOpsDays LA - Platform Engineers are Product Managers.pdf
DevOpsDays LA - Platform Engineers are Product Managers.pdf
Justin Reock
 
DevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdfDevNexus - Building 10x Development Organizations.pdf
DevNexus - Building 10x Development Organizations.pdf
Justin Reock
 
Building 10x Development Organizations.pdf
Building 10x Development Organizations.pdfBuilding 10x Development Organizations.pdf
Building 10x Development Organizations.pdf
Justin Reock
 
Open Source AI and ML, Whats Possible Today?
Open Source AI and ML, Whats Possible Today?Open Source AI and ML, Whats Possible Today?
Open Source AI and ML, Whats Possible Today?
Justin Reock
 
Community vs. Commercial Open Source
Community vs. Commercial Open SourceCommunity vs. Commercial Open Source
Community vs. Commercial Open Source
Justin Reock
 
Monitoring Java Applications with Prometheus and Grafana
Monitoring Java Applications with Prometheus and GrafanaMonitoring Java Applications with Prometheus and Grafana
Monitoring Java Applications with Prometheus and Grafana
Justin Reock
 
Integrating Postgres with ActiveMQ and Camel
Integrating Postgres with ActiveMQ and CamelIntegrating Postgres with ActiveMQ and Camel
Integrating Postgres with ActiveMQ and Camel
Justin Reock
 
Node.js Deeper Dive
Node.js Deeper DiveNode.js Deeper Dive
Node.js Deeper Dive
Justin Reock
 
ZendCon - Integration and Asynchronous Processing with ActiveMQ and Camel
ZendCon - Integration and Asynchronous Processing with ActiveMQ and CamelZendCon - Integration and Asynchronous Processing with ActiveMQ and Camel
ZendCon - Integration and Asynchronous Processing with ActiveMQ and Camel
Justin Reock
 
ZendCon - Linux 101
ZendCon - Linux 101ZendCon - Linux 101
ZendCon - Linux 101
Justin Reock
 
Ad

Recently uploaded (20)

Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Adobe Photoshop CC 2025 Crack Full Serial Key With Latest
Adobe Photoshop CC 2025 Crack Full Serial Key  With LatestAdobe Photoshop CC 2025 Crack Full Serial Key  With Latest
Adobe Photoshop CC 2025 Crack Full Serial Key With Latest
usmanhidray
 
Mastering OOP: Understanding the Four Core Pillars
Mastering OOP: Understanding the Four Core PillarsMastering OOP: Understanding the Four Core Pillars
Mastering OOP: Understanding the Four Core Pillars
Marcel David
 
Minitab 22 Full Crack Plus Product Key Free Download [Latest] 2025
Minitab 22 Full Crack Plus Product Key Free Download [Latest] 2025Minitab 22 Full Crack Plus Product Key Free Download [Latest] 2025
Minitab 22 Full Crack Plus Product Key Free Download [Latest] 2025
wareshashahzadiii
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Xforce Keygen 64-bit AutoCAD 2025 Crack
Xforce Keygen 64-bit AutoCAD 2025  CrackXforce Keygen 64-bit AutoCAD 2025  Crack
Xforce Keygen 64-bit AutoCAD 2025 Crack
usmanhidray
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Adobe Illustrator Crack | Free Download & Install Illustrator
Adobe Illustrator Crack | Free Download & Install IllustratorAdobe Illustrator Crack | Free Download & Install Illustrator
Adobe Illustrator Crack | Free Download & Install Illustrator
usmanhidray
 
Societal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainabilitySocietal challenges of AI: biases, multilinguism and sustainability
Societal challenges of AI: biases, multilinguism and sustainability
Jordi Cabot
 
Adobe Photoshop CC 2025 Crack Full Serial Key With Latest
Adobe Photoshop CC 2025 Crack Full Serial Key  With LatestAdobe Photoshop CC 2025 Crack Full Serial Key  With Latest
Adobe Photoshop CC 2025 Crack Full Serial Key With Latest
usmanhidray
 
Mastering OOP: Understanding the Four Core Pillars
Mastering OOP: Understanding the Four Core PillarsMastering OOP: Understanding the Four Core Pillars
Mastering OOP: Understanding the Four Core Pillars
Marcel David
 
Minitab 22 Full Crack Plus Product Key Free Download [Latest] 2025
Minitab 22 Full Crack Plus Product Key Free Download [Latest] 2025Minitab 22 Full Crack Plus Product Key Free Download [Latest] 2025
Minitab 22 Full Crack Plus Product Key Free Download [Latest] 2025
wareshashahzadiii
 
Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025Adobe After Effects Crack FREE FRESH version 2025
Adobe After Effects Crack FREE FRESH version 2025
kashifyounis067
 
The Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdfThe Significance of Hardware in Information Systems.pdf
The Significance of Hardware in Information Systems.pdf
drewplanas10
 
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
What Do Contribution Guidelines Say About Software Testing? (MSR 2025)
Andre Hora
 
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdfMicrosoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
Microsoft AI Nonprofit Use Cases and Live Demo_2025.04.30.pdf
TechSoup
 
Xforce Keygen 64-bit AutoCAD 2025 Crack
Xforce Keygen 64-bit AutoCAD 2025  CrackXforce Keygen 64-bit AutoCAD 2025  Crack
Xforce Keygen 64-bit AutoCAD 2025 Crack
usmanhidray
 
Download Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With LatestDownload Wondershare Filmora Crack [2025] With Latest
Download Wondershare Filmora Crack [2025] With Latest
tahirabibi60507
 
Solidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license codeSolidworks Crack 2025 latest new + license code
Solidworks Crack 2025 latest new + license code
aneelaramzan63
 
Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]Get & Download Wondershare Filmora Crack Latest [2025]
Get & Download Wondershare Filmora Crack Latest [2025]
saniaaftab72555
 
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Mastering Fluent Bit: Ultimate Guide to Integrating Telemetry Pipelines with ...
Eric D. Schabell
 
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AIScaling GraphRAG:  Efficient Knowledge Retrieval for Enterprise AI
Scaling GraphRAG: Efficient Knowledge Retrieval for Enterprise AI
danshalev
 
PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025PDF Reader Pro Crack Latest Version FREE Download 2025
PDF Reader Pro Crack Latest Version FREE Download 2025
mu394968
 
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...Exploring Code Comprehension  in Scientific Programming:  Preliminary Insight...
Exploring Code Comprehension in Scientific Programming: Preliminary Insight...
University of Hawai‘i at Mānoa
 
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& ConsiderationsDesigning AI-Powered APIs on Azure: Best Practices& Considerations
Designing AI-Powered APIs on Azure: Best Practices& Considerations
Dinusha Kumarasiri
 
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
How Valletta helped healthcare SaaS to transform QA and compliance to grow wi...
Egor Kaleynik
 
Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025Avast Premium Security Crack FREE Latest Version 2025
Avast Premium Security Crack FREE Latest Version 2025
mu394968
 
Adobe Illustrator Crack | Free Download & Install Illustrator
Adobe Illustrator Crack | Free Download & Install IllustratorAdobe Illustrator Crack | Free Download & Install Illustrator
Adobe Illustrator Crack | Free Download & Install Illustrator
usmanhidray
 

Getting Started with Node.js

  • 1. Getting Started with Node.js JUSTIN REOCK | CHIEF ARCHITECT | OPENLOGIC BY PERFORCE
  • 2. Who is this nerd?
  • 3. 3 perforce.com Justin Reock Chief Architect OpenLogic by Perforce Presenter Justin has over 20 years’ experience working in various software roles and is an outspoken free software evangelist, delivering enterprise solutions and community education on databases, integration work, architecture, and technical leadership. He is currently the Chief Architect at OpenLogic by Perforce.
  • 4. 4 perforce.com GitHub Repo for Demos • https://github.com/jreock/ getting-started-with- node.js • ColorsModule will require an “npm install” – but don’t worry I’ll teach you how to do it!
  • 6. What are we going to solve?
  • 8. 8 perforce.com Asychronous Processing • No one likes the spinning wheel of doom hope! • Node.js is inherently asynchronous, blocking actions only when it absolutely needs to • This is ideal for our new(ish) world of parallel compute, distributed compute, microservices, etc… • Built on industry standards and vetted against thousands of production systems
  • 10. 10 perforce.com A Long Time Ago… Backend Silo Front End Silo Backend Servers Front End Servers App
  • 11. 11 perforce.com Behold, The Future! DevOps Team App Farm App Node allows us to code our front end and our backend using a single language
  • 12. 12 perforce.com Node.js Overview • Created by Ryan Dahl in 2009 to address concurrency issues. • Dahl famously “built it over the weekend…” • Built on Chrome’s V8 JavaScript engine. • Single-threaded asynchronous event driven JavaScript framework. In- progress tasks can easily be checked for completion. • Vertical scaling can be achieved by adding CPU cores and adding a worker to each core. This means resources can be shared (via the cluster module and child_process.fork(…)). • Using JavaScript on the browser as well as the server minimizes the mismatch between the environments. Example: Form validation code does not have to be duplicated on both client and server. • Node.js objects maintain a list of registered subscribers and notifies them when their state changes (‘Observer’ design pattern).
  • 13. 13 perforce.com Why reinvent the wheel? • npm is the node (sic) package manager for Node.js. • npm enables JavaScript developers to share code to solve common problems promoting reuse. This allows developers to take advantage of the expertise of a large community. • Very active and vibrant community: As of February 2017, there were nearly 400,000 total packages on npm.
  • 14. 14 perforce.com • NPM is the fastest growing and most prolific module repository out there • Over a million modules and growing Source: www.modulecounts.com – August 2019
  • 15. 15 perforce.com Benefits of Node.js Pros • Lightweight: Low memory footprint • Cross-platform environment. Server and client- side can be written in JavaScript. • Fast: Asynchronous and event driven • Popularity • Concurrency implementation is abstract (handled behind the scenes). • Full Stack Web Development: Front-end developers can code on the backend. • Extensibility Cons • 1.7 GB memory limit (64-bit) • Vertical scaling challenge (but workarounds exist) • Module versions can get confusing • Open source governance is not flawless (See LeftPad) • Learning curve for developers not used to dealing with an inherently asynchronous language
  • 16. 16 perforce.com Node.js Web-Enabled Hello World var http = require('http'); http.createServer(function (request, response) { response.writeHead(200, {'Content-Type': 'text/html'}); response.end('Hello World'); }).listen(8081); http://www.haneycodes.net/to-node-js-or-not-to-node-js/
  • 19. 19 perforce.com Installing Node • This will vary by environment, but Node can be installed in several different ways: • Linux Package Manager (like yum, apt-get, pkg, emerge) • Standalone installer (https://nodejs.org/en/download/) • Official Docker Image • Standalone Shell Script
  • 20. 20 perforce.com Verifying Node Install • Once Node has been installed in your environment, check to make sure NPM has been installed as well • You can validate the installation by simply checking the version of each binary from the command line:
  • 21. 21 perforce.com Demo: A Quick Node App • Node applications can be run using the “node” command line binary • We’ll write a simple console hello world app from scratch • We’ll then execute it on the command line
  • 22. 22 perforce.com Picking an IDE • I’ll cut to the chase, I really like VSCode for Node.js development • Terminal integration is essential when building your Node apps • And the built-in debugger works flawlessly with Node.js • However, you have other options • In the end, go with what is familiar and available (and is not Notepad)
  • 23. 23 perforce.com Picking an IDE • We’ve all got our preferences, but make sure whatever you choose meets at least the following requirements: üApplication Debugger üSyntax Highlighting üESLint üTerminal Integration üNPM Integration üIntelliSense (Code Completion) üCode Beautifier üDocker Integration üNode_modules Integration üSource Control Integration
  • 24. 24 perforce.com • Cloud 9: https://c9.io/ • Online Code Editor • Debugging • Docker Integration: https://github.com/kdelfour/cloud9-docker • Live Preview • JetBrains WebStorm: https://www.jetbrains.com/webstorm/ • Code Completion • Debugger • Komodo IDE: http://www.activestate.com/komodo-ide • Nodeclipse: http://www.nodeclipse.org/ • Eclipse with Node.js Plugins
  • 25. 25 perforce.com Setting up VSCode • Countless VSCode extensions exist • Start With at least: • Node Debug • Node.js Extension Pack • Take time to explore what is out there
  • 26. 26 perforce.com Understanding Launch.json in VSCode • In VSCode, application launch configuration is controlled through a JSON file called “launch.json” • This file will be referenced before VSCode launches the app when debugging • It describes the environment the application will run in including environment variables, bootstrap information, etc • It is essential for debugging, and convenient for launching unit and functional tests
  • 27. 27 perforce.com Demo: Debugging an App in VSCode • We’ll modify our HelloWorld example to store our message in a variable • Then we’ll create a launch configuration for our project • Finally, we’ll launch our project and inspect our message variable
  • 28. 28 perforce.com Node App Basic Lifecycle • If you are using SCM • Don’t forget relevant ‘ignore’ files Create and Clone SCM Repo* • Run "npm init" in new project folder Initialize Project • Get to it! • If using SCM, commit as normal! Code! • In target production environment, run "npm install" to download necessary dependencies Build * Just create new folder if not using SCM
  • 29. 29 perforce.com Node App Basic Lifecycle * Just create new folder if not using SCM • If you are using SCM • Don’t forget relevant ‘ignore’ files Create and Clone SCM Repo* • Run "npm init" in new project folder Initialize Project • Get to it! • If using SCM, commit as normal! Code! • In target production environment, run "npm install" to download necessary dependencies Build
  • 30. 30 perforce.com Initializing a Node App • It’s development best practice to use npm to initialize a new Node.js app • This process will prompt the user for several standard pieces of metainformation about the application • Things like the application name, version, license, and bootstrap class will be collected • NPM will generate a build configuration file for the app called package.json • Package.json will describe to NPM everything needed to build your Node.js app
  • 31. Demo: Initializing a Node app • Let’s turn our HelloWorld demo into a proper Node application • We’ll run npm init in the root folder and answer the prompts • Then we’ll look at what NPM has done for us
  • 32. 32 perforce.com Understanding package.json • After running “npm init”, this file will be generated in the project root folder • Our project currently has no dependencies, but dependency information is held here too { "name": "helloworld", "version": "1.0.0", "description": "Hello World!", "main": "hello.js", "scripts": { "test": "echo "Error: no test specified" && exit 1" }, "author": "Justin Reock", "license": "GPL-3.0-or-later" }
  • 33. 33 perforce.com Working with dependencies • Our final topic will introduce dependencies, or modules • Most modern open-source languages have a set of open-source modules that can be added to a project • You can also create your own modules, whether private or freely available • Recall that the NPM repository provides these modules • NPM can also be used to add dependencies to a project, in both development and production environments, using the “npm install” command • Once NPM has installed a module into a project, a developer can begin using it with the “require” directive inside the Node.js app
  • 34. 34 perforce.com Example: Let’s Add Some Color • The “colors” module for Node adds easy support for generating console colors through escape commands • You want your console output to be readable, and even fun! • The colors module makes that easy, and we can add it with npm install • Note that the –-save directive will ensure that the module is saved to package.json npm install –-save colors var colors = require(‘colors’); console.log(colors.red.underline(‘This is red underlined text.’); or console.log(‘This is red underlined text.’.underline.red)
  • 35. 35 perforce.com Demo: Adding Project Modules from NPM • So, let’s add some color to our HelloWorld app! • We’ll use npm to install the “colors” module and make sure it’s contained in package.json • Then we’ll ”require” that module, and use it in our code • BONUS: Remove the node_modules and rebuild with npm install
  • 37. 37 perforce.com What did we learn? • Node.js is a language that focuses on concurrency and unified development • Dependencies (modules) and builds are assisted through npm • Node is asynchronous by default • Many IDEs exist for Node.js, and we have focused on VSCode • Node projects should be initialized using ”npm init” • Modules can be installed with “npm install –save [module]” • Projects are built from package.json in other environments with “npm install” • Modules are included as variables in a project using the “require” directive
  • 38. 38 perforce.com What Next? • Node is a huge subject, but, I’d focus on the following from here: • Understand Asynchronous Coding • Get to Know Events and Streams • Learn about Functional Programming • Master your IDE’s Debugger • Start Exploring Other Modules! • Still So Much to Learn!!
  • 39. 39 perforce.com Feel free to reach out -- I get lonely! LinkedIn – Only Justin Reock in the world apparently! Twitter – @jreock - But I do get a little political on there…. Blog - https://www.openlogic.com/blog Email – [email protected]