Node.js Flashcards
What is a CLI?
What is a GUI?
command line interface
graphical user interface
Give at least one use case for each of the commands listed in this exercise. man cat ls pwd echo touch mkdir mv rm cp
man - manual
cat - read files and “concatenate files”
ls - list files – options -aF to show all and any files starting with .
pwd - print working directory
echo - echos a string
touch - alters a file or directory - make blank file
mkdir - make directory – options -p to include parent directories
mv - move or rename files
rm - remove files –> rm -r remove directory -f force
cp - copy file
What is Node.js?
asynchronous event-driven JavaScript runtime
What can Node.js be used for?
used for server-side programming, and primarily deployed for non-blocking, event-driven servers, such as traditional web sites and back-end API services
What is a REPL?
read, evaluate, print, loop
where you can do calculations and stuff in a ‘terminal’
When was Node.js created?
2009
What is the process object in a Node.js program?
global variable that provides information about, and control over, the current Node.js process
How do you access the process object in a Node.js program?
type process in node command
What is the data type of process.argv in Node.js?
strings in an array
–> string array
What is a JavaScript module?
smaller JS files that do a specific thing and put together to do “somethign” as a whole
What values are passed into a Node.js module’s local scope?
exports, require, module, __filename, __dirname
Give two examples of truly global variables in a Node.js program.
process and global, console
What is the purpose of module.exports in a Node.js module?
allows the function to be import as module using require
How do you import functionality into a Node.js module from another Node.js module?
require()
What is the JavaScript Event Loop?
consists of stack, heap, and queue
code is put through a stack and uses last in first out to return functions/modules, if there is any async functions/ http requests then it goes to the heap and then once it checks out it goes to the queue. Once the stack is empty it then puts the first item from the queue to the stack then returns it
What is different between “blocking” and “non-blocking” with respect to how code is executed?
blocking is when code “blocks” the other code because the compiler waits until that blocker code completes,
non-blocking is when code runs async and gets placed on a heap then a queue to return once a stack is cleared
What module does Node.js include for manipulating the file system?
.readFile
What method is available in the Node.js fs module for writing data to a file?
fs.writeFile
Are file operations using the fs module synchronous or asynchronous?
async
npm stands for
node package manager
what is a package
directory with files with a package json
How can you create a package.json with npm?
npm init –yes
What is a dependency and how to you add one to a package?
What happens when you add a dependency to a package with npm?
a dependency is a code that project needs and “depends on” like a library if you use MATH.__()
you can add to a package using npm install “package”
when a dependency gets added it is added to package.json