Getting Started
JavaScript
ES6 concepts
Command Line
Server-side engineers
Developers experienced with browser-side JavaScript
Anyone who wants to learn Node.js
What Node is
What you can do with Node
How To Install Node
Node REPL and how to execute Node
How Node Works
Browser vs. Node
Event loop and concurrency
Advantages and drawbacks of Node
Chrome V8 Engine
Node Architecture
Client vs. Server
Single Thread
Non-Blocking
Node Binary
Libuv
BONUS
Javascript Runtime Environment
Built on Chrome's V8 Javascript Engine
Created by Ryan Dahl in 2009
Open source
Server-side scripting
Cross-platform
Persistence
The V8 engine is the open-source JavaScript engine that runs in Google Chrome and other Chromium-based web browsers, including Brave, Opera, and Vivaldi. It was designed with performance in mind and is responsible for compiling JavaScript directly to native machine code that your computer can execute.
LG’s InstaView Fridge Come with Windows 10 Tablet on the Door
Using a Node installer is the least recommended way of installing Node
The recommended way to install Node.js on macOS and Linux is by using a Node version manager, in particular nvm. See https://github.com/nvm-sh/nvm for full details.
INSTALL NVM
The way to install nvm is via the install script at https://github.com/nvm-sh/nvm. If curl is installed (it usually is) a single command can be used to install and setup nvm:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | zsh
cat install.sh | bash
cat install.sh | zsh
command -v nvm
If this fails on Linux, close and reopen the terminal (or SSH session) and try running the command again. On macOS see https://github.com/nvm-sh/nvm#troubleshooting-on-macos for in depth troubleshooting.
nvm install node # "node" is an alias for the latest version
nvm install 6.14.4 # install a specific version
node --version
node -v
Verify Node is Installed:
Node Version Switcher(nvs) is the recommended version manager for Windows. The nvs version manager is actually cross-platform so can be used on macOS and Linux but nvm is a lot more popular.
nvs add latest # latest version of node
nvs add lts # add the latest LTS version of node
nvs use lts # activate the newly installed version
node -v # verify that Node is installed
which node
REPL
Execute Files
Great for trying things out, think console on the browser, playground
It allows easy execution of any JavaScript code in a virtual environment
Just type the node command with no args and begin
Text
2 + 2
let name = 'Node'
5 === 5
const hello = () => {
return 'world'
}
.editor
function myFunction(a, b) {
return a * b;
}
function myAnotherFunction(a, b) {
return a + b;
}
myFunction(3,6)
myAnotherFunction(3,6)
.help
Number.
Array.
console.log(global)
.break
Math.random()
const num = _
num
Text
const http = require('http');
const hostname = '127.0.0.1';
const port = 3000;
const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
res.end('Hello World');
});
server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
a web framework
multi-threaded, think of it as a single threaded server (EVENT LOOP)
beginner friendly
Node.js is an event-based, non-blocking, asynchronous I/O runtime that uses Google’s V8 JavaScript engine and libuv library.
“JavaScript has certain characteristics that make it very different than other dynamic languages, namely that it has no concept of threads. Its model of concurrency is completely based around events.”
- Ryan Dahl
Client/browser
Server
2. The server responds to the client by loading a page or sending data.
1. The client makes a request to the server.
Electron, the Node.js-based wrapper around the Chrome engine, lets Node.js developers create desktop GUI applications and is the foundation on which many popular applications have been built, including the Atom and Visual Studio Code editors, GitKraken, Postman, Etcher, and the desktop Slack client.
CDN's
Shareable libraries
IOT
The following applications are built with Node.js:
CLI tools such as hexa.run and Azure Functions CLI
Back-end servers and API services such as Express.js and NestJS
Desktop apps such as Slack (using Electron)
IoT libraries such as Johnny-Five, Puck-js, and Tessel
Plug-ins for SketchApp and Adobe XD
Code editors such as Visual Studio Code and Atom
Native mobile development with NativeScript
Built-in module system(fs, http,https crypto,zip,...)
Debugger and other utilities
NPM
Command Line Interface
Module dependency manager
Node’s asynchronous non-blocking nature
Having a big package registry
Security risks
CPU intensive tasks
A VM, like V8 or Chakra
C++ and JavaScript
Node.js is single-threaded for async processing. By doing async processing on a single-thread under typical web loads, more performance and scalability can be achieved instead of the typical thread-based implementation.
Real-time chats
Internet of Things
Complex SPAs (Single-Page Applications)
Real-time collaboration tools
Streaming applications
Microservices architecture
NPM stands for Node Package Manager, responsible for managing all the packages and modules for Node.js.
Provides online repositories for node.js packages/modules, which are searchable on https://www.npmjs.com/
Provides command-line utility to install Node.js packages and also manages Node.js versions and dependencies
A callback function is called after a given task. It allows other code to be run in the meantime and prevents any blocking. Being an asynchronous platform, Node.js heavily relies on callback. All APIs of Node are written to support callbacks.
The term I/O is used to describe any program, operation, or device that transfers data to or from a medium and to or from another medium
Every transfer is an output from one medium and an input into another. The medium can be a physical device, network, or files within a system
The “require” command is used for importing external libraries.
const http = require ('http')
This will load the HTTP library and the single exported object through the HTTP variable.
The two types of API functions in Node.js are:
Asynchronous, non-blocking functions
Synchronous, blocking functions
libuv is a multi-platform support library with a focus on asynchronous I/O. It was primarily developed for use by Node.js, but it’s also used by Luvit, Julia, pyuv, and others.
Some of the features of libuv are:
Full-featured event loop backed by epoll, kqueue, IOCP, event ports.
Asynchronous TCP and UDP sockets
Asynchronous file and file system operations
Child processes
File system events
Node.js Design Patterns(book)
Node Cookbook(book)
Node.js Web Development:5th Edition(book)
Node.js The Right Way (book)
Awesome-Nodejs(github)
Stream Handbook (github)
Awesome Nodejs Learning (github)
Node Best Practices (github)
Node School (website)
30 Days of Node (website)