Downloads - Mastering Node - JS, Part 1 - Introduction
Downloads - Mastering Node - JS, Part 1 - Introduction
Produced by
Course Overview
What is Node.js?
Installing Node.js Building a Simple Web Server
Node REPL Reading Files from Disk
Node Programs Debugging
Managing Packages with NPM Creating a Package
Use NPM to run a package
What is Node.js?
JavaScript JavaScript
File Reader Audio HTTP Cluster
V8 V8
Many Many
Timers Video Timer Stream
More… More…
Installing Node.js
https://www.npmjs.com/
Local vs Global Packages
administrative privileges
Global Packages on Mac and Linux
https://docs.npmjs.com/getting-started/fixing-npm-permissions
Managing Packages with NPM
Building a Simple Web Server
One of the core modules for Node.js is the HTTP module, which
provides a web server and web client
The web server is very flexible, but requires a lot of boiler plate coding
to build even the simplest applications
Commonly, other packages such as Express or Hapi are used to
configure the web server
Web server are I/O intensive applications making them well suited for
Node.js
Node.js is great for web servers because of its easy handling of JSON
data
Building a Simple Web Server
Reading Files from Disk
Node.js allows full access to the system (such as accessing the file
system), unlike a web browser which only allows sandboxed access
Accessing file system resources can be synchronously and
asynchronously
Synchronous access can be used for initial program loading, but only
asynchronous access should be used during program operation
Both text and binary data can read and written
Full support for streams
Reading Files from Disk
Debugging Node.js
Node.js comes with a built in command line debugger, but its limited
Instead, there are many code editors and other tools which greatly
simplify debugging of Node.js applications
StrongLoop's Node Inspector (free – Windows/Mac/Linux)
Microsoft Visual Studio Code (free – Windows/Mac/Linux)
Microsoft Visual Studio with Node.js Extension (community edition free – Windows only)
GitHub's Atom with Node Debugger Package (free – Windows/Mac/Linux)
JetBrains' WebStorm (not free – Windows/Mac/Linux)
These IDEs provide the standard fare of debugging tools such as
breakpoint, call stacks, watches, and local variables
StrongLoop's Node Inspector
https://github.com/node-inspector/node-inspector
Debugging Node.js using Node Inspector
Microsoft's Visual Studio Code
https://code.visualstudio.com
Debugging Node.js using Visual Studio Code
Microsoft's Visual Studio with Node.js Extension
https://www.visualstudio.com/products/visual-studio-community-vs
Debugging Node.js using Visual Studio with Node Extension
GitHub's Atom with the Node Debugger Package
https://atom.io
Debugging Node.js using Atom with Node Debugger Package
JetBrains' WebStorm
https://www.jetbrains.com/webstorm
Debugging Node.js using WebStorm
Creating a Package
All projects (which are also packages) need to be configured to work
with NPM
The command npm init is used to configure a project
It will ask a series of questions, all of which have default answers, that
are used to create and initialize a package.json file
The package.json file contains metadata about the project, as well as,
a list of application and development dependencies
When NPM packages are installed, NPM will register them with the
package.json file
Saving Package Dependencies
Simply installing packages do not save the dependency in the
package.json file
In addition to installing, additional flags need to be specified:
--save or -S will save the package as an application dependency
--save-dev or -D will save the package a development dependency
Application dependencies are used by the Node.js program when
executing (common example would be Express)
Development dependencies are used to develop the Node.js program
(common example would be Grunt)
Saving Package Dependencies
• The terminal commands to left, will
Terminal Commands
produce a package.json file similar to Package.json