Node.js Flashcards
(44 cards)
What is Node.js?
short version: asynchronous server environment executing JS outside browser
long version: asynchronous event-driven open source server environment that executes JavaScript code outside a web browser
powered by V8 (same JS engine as Chrome browser)
What can Node.js be used for?
build back ends for:
- Web applications
- command-line programs
- or any kind of automation that developers wish to perform
Miscellaneous:
- generate dynamic page content
- create, open, read, write, delete, and close files on the server
- collect form data
- add, delete, modify data in your database
What is a REPL?
Read-Eval-Print-Loop (REPL)
interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user
executed piecewise
facilitate exploratory programming and debugging because the programmer can inspect the printed result before deciding what expression to provide for the next read
When was Node.js created?
2009
What back end languages have you heard of?
Python Java Ruby PHP JS
What is a computer process?
the instance of a program that is being executed by 1+ threads
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
a lot
400-500 MAC
200ish Windows
Why should a full stack Web developer know that computer processes exist?
Full stack Web development is based on making multiple processes work together to form one application.
This will be extremely important when learning about applications made of multiple components:
- clients
- servers
- databases
What is the process object in a Node.js program?
global object that provides information about, and control over, the current Node.js process
doesn’t need “ require() “ to access
How do you access the process object in a Node.js program?
use variable “process” & dot notation to access properties/methods
process.property
What is the data type of process.argv in Node.js?
returns ARRAY containing command line args passed when node launched
argv[0] = process.execpath (useless to us) argv[1] = path to js file being executed (useless to us) argv[2+] = addtl command line args passed (USEFUL!)
therefore always start at argv[2] bc thats where actual input starts
What is a JavaScript module?
a single js file
What values are passed into a Node.js module’s local scope?
all of these values will change for each module:
\_\_dirname ---> string \_\_filename --> string exports --> object module --> object require --> function
Give two examples of truly global variables in a Node.js program.
clear or set Interval(object)
clear or set Timeout(object)
console
process
What is the purpose of module.exports in a Node.js module?
export a function to another js file for use
How do you import functionality into a Node.js module from another Node.js module?
use REQUIRE to load content of file into memory const add = require( ' ./jsFileName ');
requires() returns what?
module.exports
if it is 1 function, returns the function
if it is object with many functions, will return the object
What is the JavaScript Event Loop?
responsible for:
- executing code
- collecting & processing events
- executing queued sub-tasks
What is different between “blocking” and “non-blocking” with respect to how code is executed?
blocking: synchronous - any additional JS code in Node.js process must wait until a operation completes
nonblocking: asynchronous - usually has a callback function
What is a directory?
a folder on our hard drive that holds files
What is a relative file path?
internal path in same directory
file path relative to where you’re currently at
(adding “ ./ “ if in current folder)
What is an absolute file path?
the FULL file path to get to a specific file/folder
path from root directory (beginning of hard drive) and every folder it takes to get to the specific file
NOTE: never hardcode an absolute path; it runs on your machine but may not on others due to different file structures
What module does Node.js include for manipulating the file system?
fs module (File System) must [require] it in if fs is needed
What method is available in the Node.js fs module for writing data to a file?
fs.writeFile