Node.js Flashcards
What is Node.js?
a cross-platform JavaScript runtime environment that allows developers to build server-side and network applications with JavaScript
Node.js is a way to execute JS outside of the browser environment
What can Node.js be used for?
back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform.
building servers or backends for web applications
What is a REPL?
Read–eval–print loop
a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the use - similar to a console.log
An example of a repl is the inspect tools.
A read–eval–print loop (REPL), also termed an interactive toplevel or language shell, is a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the user.
When was Node.js created?
2009 by Ryan Dahl
What back end languages have you heard of?
Python, C++, C#, Java, Ruby, PHP, Perl
What is the process object in a Node.js program?
- a global variable that gives info about the current node.js process
The process object is a global that provides information about, and control over, the current Node.js process.
How do you access the process object in a Node.js program?
- same way you would any object ?
- through node in the terminal
- through node in the terminal executing js file with a console.log of the object/properties
As a global, it is always available to Node.js applications without using require(). It can also be explicitly accessed using require(): const process = require('process');
process keyword
Process is a global object so you can just reference it - console.log(process)
What is the data type of process.argv in Node.js?
- an array of strings
This property returns an array containing the arguments passed to the process when run it in the command line
What is a JavaScript module?
a way of breaking javascript code into multiple files their scope is module scope (they each have their own local scope)
A JavaScript module is a single JavaScript file
What values are passed into a Node.js module’s local scope?
exports, require, module, __filename, __dirname
way loads modules, loads the raw string from the file & wraps it in in a wrapper & provides a unique value to the module with those 5 things
Give two examples of truly global variables in a Node.js program.
console
process
setTimeOut
setInterval
What is the purpose of module.exports in a Node.js module?
helps to share functions or variables between files. - insures that the code in the module is able to be seen & accessed (connected to) by other modules in the application
How do you import functionality into a Node.js module from another Node.js module?
module.exports var variable = require('path to module/module name') imports / export keywords
Module.export
require(‘./jsFile);
using the require function when you pass in a string of the ID or the path of the module you want to import
By calling the require function and passing relative path as its argument.
What is the JavaScript Event Loop?
a constantly running process that monitors both the callback queue and the call stack
What is different between “blocking” and “non-blocking” with respect to how code is executed?
A blocking assignment takes effect immediately it is processed. A nonblocking assignment takes place at the end of processing the current “time delta”. occupying the call stack.
blocking functions execute in a series whereas non-blocking functions execute concurrently.
blocking is when there is code that is slow on the call stack. this becomes an issue because blocking that stack means the browser can’t do anything while it waits for everything to run
blocking methods execute synchronously
non-blocking methods execute asynchronously
if there’s a code running, no other code can be running
blocking is anything that just sits on the call stack until it is complete
non-blocking is something that is deferred to the task queue that waits to be executed
“blocking” means script that is executed on the stack, It is “blocking” as long as it is on the stack. It is “non-blocking” when it’s not on the stack