
SECTION 1 Introduction to Installing and Setup of Node
This section is a fast paced quick intro to NodeJS, and how you start using NodeJS. We discuss what NodeJS is and that it is not a programming language like JavaScript is but an interpreter and Environment for JavaScript.
Node is a lightweight framework developed on Chrome’s V8 engine that can be used for largeScale application development. It's scalable because the server can respond in a non-blocking way.
Process object which is a global that provides information, and control over, the current Node.js process. Because its global it is always available to Node.js applications without using require()
npm registry contains packages, many of which are also Node modules, or contain Node module
Demo how to setup your development environment setting up Editor
Visual Studio Code as an Editor with ready terminal
Creating your first Node File and running the code
How Node Works and examples of simple node syntax
Where you can find out more about Node with more examples.
How to debug and output content into the terminal various command line and console outputs
NodeJS programming language environment REPL Read Evaluate Print Loop
Examples of Node
Process Object - with examples
What Node Packages and NPM
Setup and introduction to getting started with Node Node website odejs.org
Editor Visual Studio Code
NPM - setup https://www.npmjs.com/
Terminal Command+Space or Windows
Check Node Version and NPM version node -v and npm -v
How to use Visual Studio Code
Open and access Terminal in Visual Studio code
Editor VIsual Studio Code
Setup JS file for Coding
Create a first js file
How to run a node js file
Terminal setup
Console.log in browser and in terminal
Use of console.log to output content into console
ls or dir to list files within the current directory using the terminal
node app.js running a node file.
Node code and how it runs on your machine
V8 engine
Asynchronous and non Blocking
Benefits of Node
Why node is a good choice
Node applications.
V8 Chrome and Node
History of Node
Browser document object DOM
Selecting page element
Window Object in browser
No window object in Node
Node global object
Non Blocking Asynchronous
Speed difference
CTRL+C to exit from node application
Run Node Application node appNAME.js
Create console.log message
Create Loop - stop loop with CTRL+C
Process object within node - process.exit()
for loop and using exit to break loop
Node JS REPL
Type node in the terminal
To get help .help in REPL mode
REPL also known as Read Evaluate Print Loop is a programming language environment
console. Press tab to get a list of available functions.
global. +tab to get list of available functions within global object
console option in REPL
Global Object in Node
Math in the terminal
Common Node Examples
Filename and dirname
Locate file location to use within node application
Use of node documentation for examples and code samples
Node global object
__dirname get directory of current file
__filename get filename of current file
The process object is a global that provides information about, and control over, the current Node.js process
Process argv - output and use process values within node application
process.pid
Logging process argv by index using console.log
template literal for strings ${} backticks `
Use Node Packages NodeMon
nodemon is a tool that helps develop node.js based applications by automatically restarting the node application when file changes in the directory are detected.
Search at https://www.npmjs.com/
How to install packages
npm install -g nodemon
nodemon app.js
Use of sudo prefix for admin on Mac
-g global flag
Command Line and Console
Type code directly within REPL mode
Use of Console.log to debug and output to terminal console
Console API options https://nodejs.org/dist/latest/docs/api/console.html
Log, warn, info, table and count
console.log %s use of string placeholder
console.count()
console.clear()
console.table()
console.warn()
console.info()
JavaScript Fundamentals quick review of JavaScript Coding
Explore the fundamentals of JavaScript and writing JavaScript code within the Node. Loaded with examples about the basics of coding JavaScript. Back to the basics of JavaScript code . Because node uses JavaScript code this section will provide a refresher and quick overview of JavaScript. Designed to cover the core JavaScript required for the upcoming sections and writing Node.
Variables and the Data Types. How to declare variables and examples of different Data Types.
Adding Comments to code
How to create Objects and Array
What JavaScript Functions are and how they work
Advanced Functions Immediately invoked Function Expression IIFE, Arrow format for functions, JavaScript Closure example
Different JavaScript operators and examples
Use of conditions for logic, turthy and falsey. How to use the Ternary Operator.
Examples of logic switch statement, and condition statement
JavaScript loop Structures For Loop, While Loop, DO-While Loop with code examples
Use of Objects and objects with methods.
JavaScript Arrays, adding, updating and removing items from an array. lots of commonly used useful array methods for array manipulation.
Array and Object Values, iterating through the contents of each.
Use of Template literals to set string values
Math and Data Method examples, generating random numbers and dates in JavaScript
Global object in Node with the use of timeout
Event Queue and Asynchronous operations with JavaScript
Examples of JavaScript Node Timer module
How to Construct promises and Resolve and Reject Promises
Debugging - use of Try, Catch, Finally which are used to handle exceptions in the JavaScript
JavaScript Async and Await examples and how the order of output on promise completion.
Variables and Data Types
How to declare a variable
Assign New Values to a Variable
What Variables are and how to use them
Comments and multiline comments
Quotes and Strings
const, let, var
typeof operator
Data Types
declare variables
Variables and Data Types
Strings, numbers, booleans
Variables let const - var - assign values
Rules for Declaring Variables
Data type typeof ""
ReAssign new values = assign values
Arrays Objects Data Types
Strings, numbers, booleans, arrays, objects
Intro to arrays and objects
Dynamic type conversion
Blocks of code with {} brackets
Scope within blocks
Create an object
Create and array
Add string with number
Introduction to Javascript Functions
Functions - invoke blocks of code
Function scope
Function arguments
Invoking functions with ()
Passing parameters to functions
Function Declarations vs. Function Expressions
Return response callback on functions
Javascript Functions Advanced Features
Function expressions
Function declarations
Immediately invoked Function Expression IIFE example
(function()){})() IIFE example
Modern Function Examples
Arrow format for function ES6+ (e)=>{}
Function recursion
Function invoking within itself
Use of return
Loop of function
Javascript Closure Example
How to create a JavaScript closure
Anonymous Functions
JavaScript Function Arrow format
Use of JavaScript Closures
Closure gives you access to an outer function’s scope from an inner function
Closures are created every time a function is created
Associate data with a function that operates the data
Javascript Operators
Assignment operators
Short format for adding subtracting
Remainder (%) returns the remainder left over when one operand is divided by a second operand
Modulus % Operator: var1 % var2
Examples of various assignment operators
Adding/Subtracting with shorthand methods ++ += -- -=
Multiplication * division /
Javascript More Operators Examples
Joining strings together
String concatenation
Comparison operators with data type absolute and regular. Comparison operator compares its operands and returns a Boolean value based on whether the comparison is true.
Logical operators and and or and logic not. Logical AND && Logical OR ||
Equality operator Equality operator == Inequality operator != Identity operator === Nonidentity operator !==
Conditions Truthy and Falsey
Truthy and Falsey
The if statement executes a statement if a specified condition is truthy. If the condition is falsy, another statement can be executed.
Condition statements if else else if conditions
Check condition within function return results
Ternary Operator
condition ? exprIfTrue : exprIfFalse
Ternary operator
JavaScript operator that takes three operands
Executes express for True or if condition is false.
Used commonly as shortcut for if statement
3 operands: condition followed by a question mark (?), expression to execute if the condition is truthy followed by a colon (:), lastly the expression to execute if the condition is falsy
JavaScript Switch Statement
Create a switch statement
Test results in case
Check for a match result run code
Use of break to separate the case response
Use of Default in case not match was found
switch statement evaluates an expression
JavaScript Loop For Do While
Loops run blocks of code over multiple iterations
For loop
Decreasing loop
Do while loop vs While Loop what is the difference
Quick and easy way to do something repeatedly
JavaScript Objects
Add values into JavaScript object
Named pair values name:value
Create object
Update object data
Copy object
Bracket notation vs Dot Notation
https://jsonlint.com/
Dynamic Object property names
JavaScript Object Methods
objectName.methodname = functionName;
Object Functions
Use of ‘this’ JavaScript keyword within an object
Create an object with object nested inside
Return values from Object
Add a function within the object
Return values from object using object values
JavaScript Array Introduction
How to create a JavaScript Array
Update Values of Array
Use of index value to select from the array
Array holds number strings objects booleans and other data types
Typeof Array is object
Select item from array with index value
Single objects that contain multiple values stored in a list
Arrays consist of square brackets and elements that are separated by commas
JavaScript Update Array
Add to the end of the array push method
Remove from the end of an array with response value pop method
Add to the beginning of an array unshift method
Remove from the beginning of an array shift method
Add/Remove from array starting at index value with splice
pop() method removes the last element from an array and returns the value
push() method adds a new element to the end of an array
shift() method removes the first array element
unshift() method adds a new element to the start of an array
JavaScript Delete and Add to an Array
How to remove contents from an array
Assigning values to array item using index
Array splice method
Update items and remove items from array with splice
Common JavaScript Array Method
Common JavaScript Array Methods
Use of Array Methods
Several of the built-in array methods
JSON parse and JSON stringify to convert to object and back to string
Array toString methods toString
Array join
Array concat
Array methods join to create a string with separator
Concat method to merge 2 arrays together or duplicate contents of one array
More JavaScript Array Methods
includes() return boolean
indexOf() get index value of item in array
Check if object is an array isArray()
Useful methods for array
Array Method Update Array
Copy and create new array
Update array order with sort() and reverse() methods
Get index value of item get lastIndexOf and IndexOf item in the array
Check to see if item is within an array with includes and indexOf methods
Array examples
JavaScript Empty Array Map Method
How to remove contents from an array
Use of map to iterate array contents and create a new array
Use of Array Method Map Method
map() method creates a new array populated with the results of original array
Array and Loops to create array data
Assigning values to array item using index
Array Iteration and Object Values
Loop through and get contents of an array
For loop with Array contents
array.forEach get array contents
JavaScript Objects for in loop for objects
Use of JavaScript Object.entries(myObj)
Object to Array with Keys and Values from Object Object.keys(myObj)
Other values from array forEach((val,index,arr)
JavaScript Template Literals
Use of expressions within template literal
Template literals (Template strings)
Template literals are string literals allowing embedded expressions.
You can use multi-line strings and string interpolation features with them.
Use of multiple lines
Output content in string
JavaScript Math Method
Use of Math random to generate random number
Math floor ceil to round up or down from random result
Create a random number generator function
Math.floor(x)
Math.ceil(x)
JavaScript Date Method
JavaScript Date objects represent a single moment in time
Create date object
Get time from date object
Set date object values
Date objects contain a Number that represents milliseconds since 1 January 1970 UTC
JavaScript Asynchronous Callback Examples
Global object in Node
Setup of setTimeout()
Run function after timer
Dynamic values in functions
Terminal output order
Variable update effects
JavaScript runs tasks on a single thread, called the main thread
Asynchronous operations like promises are put into an event queue, this runs after the main thread has finished processing.
Event queue only runs after the main thread so they do not block subsequent JavaScript code from running.
JavaScript Node Timers Global
The timer module exposes a global API for scheduling functions to be called at some future period of time.
Timer functions use internal implementation that is built around the Node.js and function similar to what you might see ina browser.
Global object in Node setImmediate()
Set interval and clearInterval
JavaScript Node Set Timeout clear timeout examples
Global timers with Node
JavaScript Promises
Promise object represents the eventual completion (or failure) of an asynchronous operation and its resulting value.
Construct promises
Resolve and Reject Promises
JavaScript Promises new Promise
JavaScript Try and Catch Debugging
The try...catch statement marks a block of statements to try and specifies a response should an exception be thrown.
Code debugging
Catching and throwing errors
Try and Catch statements
try lets you test a block of code for errors.
catch ets you handle the error.
throw lets you create custom errors.
JavaScript Async and Await
Adding async to add promises to functions
Set Timeout within function
Add promise to resolve
Return on completion
Order of output to console
Use of them once a promise is completed.
JavaScript Asynchronous programming
Asynchrony, in computer programming, refers to the occurrence of events independent of the main program flow and ways to deal with such events. How to add callbacks that run once a stack is complete.
Covering Input Output which accesses anything outside the application. Once the application is started it will be loaded into the machine memory.
Coding Examples, and practice code outputting into the console when ready
Event Driven programming which makes Node.js fairly fast compared to other similar technologies. Once the application starts it initiates its variables, declares its functions and then waits for the event to occur.
The two types of API functions in Node.js, Asynchronous, non-blocking functions and Synchronous, blocking functions.
The differences between blocking and non-blocking calls in Node.js.
Blocking occurs when the execution of additional JavaScript in the Node.js process must wait until a non-JavaScript operation completes. The event loop is unable to continue running JavaScript while a blocking operation is occurring. All the IO methods in node.js provide asynchronous versions, which are non-blocking.
Node keeps an event loop, which monitors when a task gets completed, which would then fire the corresponding events. Node.js overcomes the problem of blocking of I/O operations by using the event loop instead of threads.
Recursive functions, Function that calls itself is called a recursive function - must have a condition to break the loop.
The EventEmitter module makes possible the communication and interaction between objects in Node. EventEmitter provides properties like on and emit. The on property is used to bind a function with the event and emit property is used to fire an event.
NodeJS works on the Google v8 environment utilizing JavaScript as its scripting language.
How a callback works, Callback added to the background will run once stack is complete
Use of setTimeout and how it works in the queue.
Callback example Create a function that returns the results from another function
Event Loop with an Example of a Recursive Function
The three states of promises
How to create promises and more promises examples
Node process object
Node Event EventEmitter
how to setup events and trigger emit of events
Callbacks Stack and Queue
Asynchrony, in computer programming, refers to the occurrence of events independent of the main program flow and ways to deal with such events.
Use of setTimeout to delay processing way for callback
SetTimeout to zero still adds to the queue and will get run after the initial stack is completed
Async and sync examples with array data to output order of contents to console.
Adding to the queue vs stack
Single thread - process one at a time
Callback added to the background will run once stack is complete
SetTimeout is not part of V8 - its part of Node which allows us to use the runtime to sent requests to the stack and handle the response callback
if stack is empty then goes to task queue and runs it.
Stack and Queue Examples
MDN documentation
JavaScript Single Thread (main thread)
SetTimeout example into the console moving from queue to stack
Examples and practice code output to console when ready
Callback example in JavaScript
Create a function that returns the results from another function
Sequence and order of results from function callbacks.
Simple Callback model to illustrate Node Process model off single thread
Calls Event Loops Job Function
Event loop checks call stack
Event loop give priority to call stack - only once the stack is completed and nothing is there then it checks the queue.
Event Loop Example Recursive Function
The event loop is what allows Node. js to perform non-blocking I/O operations
Event loop can be asynchronous and have non-blocking I/O
Event loop continuously checks the call stack to see if there are any functions that need to run.
Recursive function max stack errors
Function that calls itself is called a recursive function - must have a condition to break the loop.
Condition to return and break recursive loop
Job Queue Event Loop Function Execution
Intro to event loop and function execution examples
setTimeout
SetImmediate
nextTick process methods
Promise and Resolve and Reject.
A Promise is in one of these states:
pending: initial state, neither fulfilled nor rejected.
fulfilled: meaning that the operation was completed successfully.
rejected: meaning that the operation failed.
The Node.js Event Loop, Timers, and process.nextTick()
The event loop is what allows Node.js to perform non-blocking I/O operations — despite the fact that JavaScript is single-threaded
Call Stack Output Order Examples
Recursive function testing with Job Queue
Immediately Invoked Function Expression IIFE Example
Setting Timeout to output to terminal
Output to terminal testing examples
JavaScript Promises
How to create a promise
Resolve and Reject on Promise
Use of Promise Callback
Use of then and catch to handle errors and responses for promise
Promise object represents the eventual completion or failure of an asynchronous operation and its resulting value
Node Process Object Terminal Input Output
The process object is a global that provides information about, and control over, the current Node.js process. As a global, it is always available to Node.js applications without using require().
Use of readline to create terminal input and output
Create readline questions and response
Process on exit and before exit
Process env and process properties
Node Event EventEmitter
The EventEmitter is a module that facilitates communication and interaction between objects in Node
Add new EventEmitter to code
Require events
Emit events
Send Arguments to events
Use of SetTimeout to setup events
Setup Node Events
Any function passed as the setImmediate() argument is a callback that's executed in the next iteration of the event loop
Loop of Events
After stack event loop is complete run event with setImmediate
Example of Node event setup
Looping event code
Events module require
EventEmitter()
on event trigger
Emit on event trigger
Node Modules NPM
Each module in NodeJS has its own context and cannot interfere with other modules. Modules are like libraries that you can include into your application. Node.js has a set of built-in modules which you can use without any further installation like http, fs, path, and url.
You can create your own modules, and easily include them in your applications. Save them locally and use them within your node application as needed. Perfect to separate functionality for your application. To make properties and methods available outside the module file use the keyword exports.
NPM hosts thousands of third party modules, free packages to download and use. A package in Node.js contains all the files you need for a module.
Debugging - The try...catch statement marks a block of statements to try and specifies a response should an exception be thrown.
How you can create your own module locally
Commonly used builtin modules like http, fs, path and url
Using FS module to update file contents, delete files, create new files
Getting file information including file size with fs.stat()
Use of node package manager NPM explore some popular node packages.
Use of package.json - adding and removing packages
Node Package Manager Module lodash
Node Buffers how to copy and slice buffer contents
Debugging node use of Throw, try and catch
Node Modules
Modules are the building block of any node application and are loaded by using require statement
How to create your own Node. js module
Writing simple modules
Modules and Objects
Local Module example
Node Modules Types
Local Module simple setup create your own modules
Core Built-in Module use of modules (http, url, path, fs, util) You need to import the core module first in order to use it in your application
Third Party Modules (express, gulp, lodash, async, socket.io, mongoose) Third party modules can be install inside the project folder or globally
Exports in modules
Module object
Use function from local module
Use Data object from local module
Local Node Modules
Module exports
Export single module
Use of local module function
Use of local module variables
Require of module
Same function name modules
Local Node Modules Exports Class
Create a class
Construct and object to use from module
Export single module anonymous function
Module exports are the instruction that tells Node. js which bits of code are exported
Core Modules http web Server Setup
Use of http module
Built in modules core node modules
Create web server with node
Route of files with conditions
Change of ports
Use of request module for json
Output of json to web server from JavaScript object
Make a Folder File System
fs module provides functionality to access and interact with the file system
file system on your computer
mkdirSync() create folder
Check if the folder exists.
Get folder files names in array
Folder directory contents
const fs = require('fs')
Node FileSystem Examples
file system on your computer
Check Folder Directory fs.readdir()
Read files fs.readFile()
Create files fs.appendFile() - will create if it does not exist
Create multiple files using a loop
File maker function example
fs module is responsible for all the asynchronous or synchronous file I/O operations
Update the contents of a file
Update files fs.appendFile() add to content
Replace Content fs.writeFile()
Create a logging function that writes into a file
Create files fs.appendFile()
Overwrite file and create it
Adding new files
Create logging file
Delete files using the file system
Delete files fs.unlink()
delete file function code example
readdir get files from the directory
loop through contents of the directory get all the files
Create a function to remove files in the folder.
Rename files using Node
Content fs.writeFile()
Rename files fs.rename()
Other IO Operations
Example code creates a function to rename all files in the folder.
File System Stats
Output html file in http web browser
fs.stat()
Get file from directory
createServer http
Fs read files and create output
require('fs')
Create HTTP output from file
stats.isFile()
stats.isDirectory()
stats.size
Reading Files FS module
Read file contents readFileSync
fs.readFile() and fs.readFileSync() read contents of the file in memory
Reading a file
Create add to File contents with array items
Read contents of new files
File and Folder Paths
Use of Path module
Get dirname() basename() extname()
Path Resolve
require('path')
Files on File System
Node Package Package.json Fetch
Adding dependency in package.json
npm help init
npm install <pkg>
npm install node-fetch
npm init -y - creates create a package.json file in the director
npm init - to setup package.json
Package.json is actual JSON file
Installing packages globally
Create JSON
--save at the end of the install command to add dependency entry into package.json
Node Package Manager Module
The Node Package Manager
Once the package is installed, it is ready to use
Include the package into your code with require()
Searching for modules
Package.json
Installing Packages Locally
npm install <package name>
NPM are installed under node_modules
npm install -g global install flag
npm update <package name> update package
Remove package npm uninstall <package name>
Create package.json npm init - to setup package.json
$ sudo npm i -g npm
$ sudo npm i --save lodash
Node Buffers
A buffer is an area of memory
Buffer.from()
Output Buffer memory
Copy Buffer contents
Slice Buffer Contents
Errors Throw try and Catch
Try and catch
Custom errors
Extend error
Debugging in node
How to throw errors
Extending errors to create custom errors
Node Web Application with Express
Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. Explore how to setup a web application quickly with Express.
The arguments which are available to an Express JS route handler function are request (request Object), response (response Object) and optional Next which can pass control to one of the subsequent route handlers.
How to setup express and output html into a localhost webpage
How to Serve files from a static directory using Express
Values that can be used in route filtering, pattern match and reg exp
Route parameters with req.params
Express Route with full CRUD Create Read Update Delete Methods
Returning JSON response
Use of bodyparser
Sending data from a frontend form to node express to output into the terminal
Returning a JSON response to the frontend from a frontend request
Express Setup
Installing express expressjs
npm install express --save
Fast minimalist web framework for Node.js
Easy to configure and customize
npm install -g express
Serving Files with Express Framework
Creating a static route
__dirname to get current file directory
Path join to create file path
res.sendFile response send file from folder
Create and return page output
Express Routing
Routing and layers in express
Routing basics
Pattern matching in routes
Route parameters
Reg expression in URI
app express() get routes
Return response send html back
Multiple CallBack Functions
Next() adding callbacks
use of req.params
get the id
request and response within callback
passing req.params into callback
Express Route Handler GET
CRUD put post delete get
Create (POST) - Make something
Read (GET)- Get something
use of __dirname
response sendFile() on get method
create HTML file
user and users routes send response
Test webapp in browser
Express Route POST
CRUD Create (POST) - Make something Read (GET)- Get something
Update (PUT) - Change something Delete (DELETE)- Remove something
BodyParser
POST from web page
Bodyparser to get POST form data
Response with URI params
Express Route Update Delete
Update (PUT) - Change something
Delete (DELETE)- Remove something
Frontend Document add event listener
Frontend fetch method to connect to endpoint route
fetch for send update and delete method data
Create routes for user with request params
Client side index AJAX fetch
Return JSON response to AJAX request
JSON Data POST Values
Array Methods filter and some
Response json() method
Return json data
Request endpoint with params
Response json data
Filter some array functions
Return matching results from javascript object
Output JSON URL Params
Loop through data from the response JSON
Output Server side response to web page
Get route with request params
Frontend fetch request for AJAX
Adding frontend browser event listeners
Custom module with data for app
MiddleWare POST with bodyParser
Additional middleware functionality
Ordering of middleware
var bodyParser = require("body-parser");
npm install body-parser --save
Create your own middleware
Express routes Router
chained route handlers
using app.route()
express.Router
express.Router()
Middleware express.Router()
Express application generator
npm install -g express-generator
express -h or express to run
express --view=pug testApp
quick start and way to develop Express JS applications
Express Generator is also a Node JS Module
Quickly create an application skeleton
npm install -g express-generator
MongoDB with Frontend web page interaction using Node and Express
The official MongoDB Node. js driver allows Node. js applications to connect to MongoDB and work with data. The driver features an asynchronous API which allows you to access method return values through Promises or specify callbacks to access them when communicating with MongoDB.
How to setup a cloud base mongo Database to use in practice development
Connecting to a mongoDB
Use of mongoDB client in Node
Checking a connection to the database
How to connect to a MongoDB and select the collections, create collections
How to output database collections to the frontend using Express and Node.
Creating a fully functional node application that uses Express to run a web application. Connect to a MongoDB and using Node allow the frontend web application to access the Database items, full CRUD interaction.
Setup Get Started with MongoDB
Setting up Mongo DB
Installing MongoDB
Using MongoDB in Node.js
MongoClient = require('mongodb').MongoClient;
It's all JavaScript
Understanding the Basic Operations
sudo npm i express
sudo npm i body-parser
sudo npm i mongodb
Setup Express Server
Ready for Database
Create MongoDB in the Cloud Create MongoDB in the Cloud
Access cloud database mongodb.com
MongoDB Atlas is the global cloud database service for modern applications.
Deploy fully managed MongoDB
Free MongoDB online
Connect and Create MongoDB Connect and Create MongoDB
MongoClient.connect()
Connecting and creating a database
const mongo = require('mongodb');
Setup of Database user and password
Key and Path to connect to cloud database
Create collection of Data
MongoClient = require('mongodb').MongoClient;
Structuring your data for MongoDB
Creating Collections
Inserting documents into collections
Accessing collection
insert to cloud Database collection
client.connect using Mongo
WebPage App to Database Setup WebPage App to Database Setup
setup express server
Output index page to browser
Setup users route
Database connect to client table and collection
Setup CRUD routes
Setup BodyParser middleware
Database insertOne into collection MongoDB
JSON.stringify results into console
Send JSON results back to client side
Setup HTML web page to request data
AJAX with eventListener to trigger request
WebPage AJAX to Endpoint
insertOne JS object
app.use(bodyParser.json());
Document Object DOM
JavaScript web page AJAX request
addEventListener to page element
Fetch request to node route users
Send headers as json data
Setup of data from webpage
Check Cloud Database insert of item
AJAX Post setup to Database
AJAX Post
test headers
Test request to Node and Database insert
JSON. stringify
Ajax get Mongo Data Ajax get Mongo Data
Frontend AJAX setup Fetch
Database results
toArray() return results as array
Use find()
Send as JSON
Web Page document createElements for output of response results
Add eventlisteners to page elements
Dynamic Page Elements AJAX
Create output using the DOM
Making Page elements interactive with event listeners
Setup for DELETE method and PUT to node
Find matches from MongoDB Get
Find using req.params
JSON results
Return matches to webpage
Output content to webpage
Update MongoDB Data Update MongoDB Data
findOneAndUpdate()
$set value
Req.body._id
AJAX fetch PUT method
Send to node application put data
Using _id as unique finder for items in MongoDB
Delete remove data from mongoDB with AJAX
deleteOne()
_id: ObjectId(req.body._id)
Delete method with AJAX
myDB.deleteOne()
More with MongoDB documents and Coding
mongodb.com/manual/
db.inventory.updateMany()
Update multiple documents
NodeJS is built for performance. NodeJS allows you to build complex and powerful application quickly and easily writing JavaScript code. NodeJS allows you to use JavaScript for not only web applications with the flexibility for a wide range of different purposes. Node brings JavaScript to the server, using Googles V8 engine.
Enroll now to get instant access to:
13.5+ hours of premium lessons
128 page downloadable workbook Guide source code, tips, resources and challenges
Premium instructor support to help you learn
Lifetime access to course updates
Top Reasons for using Node.JS
In Demand Skillset - used by popular and large businesses
NodeJS is written in JavaScript which makes the transition to Node take less time if you are already familiar with JavaScript.
Perfect solution for a full stack developer dealing with backend and databases
JavaScript is easy to start with a write code and run code within your own computer
Easily to develop locally
Open Source with an active community and support
Node Package Manager can allow you to create complex applications using existing modules, NPM has a massive number of packages.
Node is well supported, large size community and many forms and groups to share code and get help
Can be used to build micro services
Final Project in Section #6
Creating a fully functional node application, that uses Express to run a web application. Connect to a MongoDB and using Node allow the frontend web application to access the Database items, full CRUD interaction.
Create a web application using Express - output html file from public folder
Setup a MongoDB in the cloud prep to connect using NodeJS
Create and test insert into the database
Setup Frontend web application
Add DOM event listeners to trigger requests
Generate visual response as HTML from the Node response object
Update and create interactive list of database content CRUD
Add HTML updates to send requests to database.
Create (POST)
Read (GET)
Update (PUT)
Delete (DELETE)
#1 Introduction to Installing and Setup of Node
This section is a fast paced quick intro to NodeJS, and how you start using NodeJS. We discuss what NodeJS is and that it is not a programming language like JavaScript is but an interpreter and Environment for JavaScript.
Node is a lightweight framework developed on Chrome’s V8 engine that can be used for largeScale application development. It's scalable because the server can respond in a non-blocking way.
Process object which is a global that provides information, and control over, the current Node.js process. Because its global it is always available to Node.js applications without using require()
npm registry contains packages, many of which are also Node modules, or contain Node module
Demo how to setup your development environment setting up Editor
Visual Studio Code as an Editor with ready terminal
Creating your first Node File and running the code
How Node Works and examples of simple node syntax
Where you can find out more about Node with more examples.
How to debug and output content into the terminal various command line and console outputs
NodeJS programming language environment REPL Read Evaluate Print Loop
Examples of Node
Process Object - with examples
What Node Packages and NPM
#2 JavaScript Fundamentals quick review of JavaScript Coding
Explore the fundamentals of JavaScript and writing JavaScript code within the Node. Loaded with examples about the basics of coding JavaScript. Back to the basics of JavaScript code . Because node uses JavaScript code this section will provide a refresher and quick overview of JavaScript. Designed to cover the core JavaScript required for the upcoming sections and writing Node.
Variables and the Data Types. How to declare variables and examples of different Data Types.
Adding Comments to code
How to create Objects and Array
What JavaScript Functions are and how they work
Advanced Functions Immediately invoked Function Expression IIFE, Arrow format for functions, JavaScript Closure example
Different JavaScript operators and examples
Use of conditions for logic, turthy and falsey. How to use the Ternary Operator.
Examples of logic switch statement, and condition statement
JavaScript loop Structures For Loop, While Loop, DO-While Loop with code examples
Use of Objects and objects with methods.
JavaScript Arrays, adding, updating and removing items from an array. lots of commonly used useful array methods for array manipulation.
Array and Object Values, iterating through the contents of each.
Use of Template literals to set string values
Math and Data Method examples, generating random numbers and dates in JavaScript
Global object in Node with the use of timeout
Event Queue and Asynchronous operations with JavaScript
Examples of JavaScript Node Timer module
How to Construct promises and Resolve and Reject Promises
Debugging - use of Try, Catch, Finally which are used to handle exceptions in the JavaScript
JavaScript Async and Await examples and how the order of output on promise completion.
#3 JavaScript Asynchronous programming
Asynchrony, in computer programming, refers to the occurrence of events independent of the main program flow and ways to deal with such events. How to add callbacks that run once a stack is complete.
Covering Input Output which accesses anything outside the application. Once the application is started it will be loaded into the machine memory.
Coding Examples, and practice code outputting into the console when ready
Event Driven programming which makes Node.js fairly fast compared to other similar technologies. Once the application starts it initiates its variables, declares its functions and then waits for the event to occur.
The two types of API functions in Node.js, Asynchronous, non-blocking functions and Synchronous, blocking functions.
The differences difference between blocking and non-blocking calls in Node.js.
Blocking occurs when the execution of additional JavaScript in the Node.js process must wait until a non-JavaScript operation completes. The event loop is unable to continue running JavaScript while a blocking operation is occurring. All the IO methods in node.js provide asynchronous versions, which are non-blocking.
Node keeps an event loop, which monitors when a task gets completed, which would then fire the corresponding events. Node.js overcomes the problem of blocking of I/O operations by using the event loop instead of threads.
Recursive functions, Function that calls itself is called a recursive function - must have a condition to break the loop.
The EventEmitter module makes possible the communication and interaction between objects in Node. EventEmitter provides properties like on and emit. The on property is used to bind a function with the event and emit property is used to fire an event.
NodeJS works on the Google v8 environment utilizing JavaScript as its scripting language.
How a callback works, Callback added to the background will run once stack is complete
Use of setTimeout and how it works in the queue.
Callback example Create a function that returns the results from another function
Event Loop with an Example of a Recursive Function
The three states of promises
How to create promises and more promises examples
Node process object
Node Event EventEmitter
how to setup events and trigger emit of events
#4 Node Modules
Each module in NodeJS has its own context and cannot interfere with other modules. Modules are like libraries that you can include into your application. Node.js has a set of built-in modules which you can use without any further installation like http, fs, path, and url.
You can create your own modules, and easily include them in your applications. Save them locally and use within your node application as needed. Perfect to separate functionality for your application. To make properties and methods available outside the module file use the keyword exports.
NPM hosts thousands of third party modules, free packages to download and use. A package in Node.js contains all the files you need for a module.
Debugging - The try...catch statement marks a block of statements to try and specifies a response should an exception be thrown.
How you can create your own module locally
Commonly used builtin modules like http, fs, path and url
Using FS module to update file contents, delete files, create new files
Getting file information including file size with fs.stat()
Use of node package manager NPM explore some popular node packages.
Use of package.json - adding and removing packages
Node Package Manager Module lodash
Node Buffers how to copy and slice buffer contents
Debugging node use of Throw, try and catch
#5 Node Web Application with Express
Express is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. Explore how to setup a web application quickly with Express.
The arguments which are available to an Express JS route handler function are request (request Object), response (response Object) and optional Next which can pass control to one of the subsequent route handlers.
How to setup express and output html into a localhost webpage
How to Serve files from a static directory using Express
Values that can be used in route filtering, pattern match and reg exp
Route parameters with req.params
Express Route with full CRUD Create Read Update Delete Methods
Returning JSON response
Use of bodyparser
Sending data from a frontend form to node express to output into the terminal
Returning a JSON response to the frontend from a frontend request
#6 MongoDB with Frontend web page interaction using Node and Express
The official MongoDB Node. js driver allows Node. js applications to connect to MongoDB and work with data. The driver features an asynchronous API which allows you to access method return values through Promises or specify callbacks to access them when communicating with MongoDB.
How to setup a cloud base mongo Database to use in practice development
Connecting to a mongoDB
Use of mongoDB client in Node
Checking a connection to the database
How to connect to a MongoDB and select the collections, create collections
How to output database collections to the frontend using Express and Node.
Creating a fully functional node application that uses Express to run a web application. Connect to a MongoDB and using Node allow the frontend web application to access the Database items, full CRUD interaction.