Node Flashcards
What is Node.JS?
A program that allows JavaScript to be run outside of a web browser
What can Node.JS be used for?
Commonly used to build back ends for Web Applications, command-line programs, or other automation software developers wish to perform
What is a REPL?
Read, Eval, Print loop —> also termed a ‘language shell’
When was Node.JS created?
May 27, 2009 —> created by Ryan Dahl
What backend languages have you heard of?
Python, Ruby, Java, PHP, C, C++, c# (.net), JavaScript (&Node)
What is the process object in a Node.JS program?
A global that provides information and control over the current node.JS process
What is a ‘process’?
Any one program that your computer is running at a given time
When you execute a file with node, you start a…
Process!
How do you access the process object in a Node.JS program?
It’s globally available, so you can just type ‘process’ (although it also can be required in)
What data type does process.argv return in node.JS?
It returns an array containing command line args passed in when the process was launched
What will process.argv[0] be?
The path to node’s executionable file
What will process.argv[1] be?
The path to the JavaScript file being executed
What will process.argv[2] onwards be?
Any command line arguments
Every index in the argv array always is… (data type)
A string
What is a JavaScript module?
A module is a single .JS file.
All modules are wrapped in a…
Function
What values are passed into a Node.JS module’s local scope via the wrapping function?
exports, require, module, __filename, __dirname
Give two example of truly global variables in a Node.JS program.
Process & console objects (global, setTimeout, setInterval)
What determines what is returned by .require(‘file-path’)?
Whatever is stored in the module.exports variable in the file specified.
Will variables between files collide?
No —> because each file is wrapped in a function, they have their own unique scope
What is the purpose of module.exports in a Node.JS module?
It allows you to export code out from one module
How do you import functionality into a Node.JS module from another Node.JS module?
- Set module.exports = ‘what-to-export’
- Use the require keyword with the file path passed in as the argument
What is the JavaScript Event Loop?
It allows JavaScript to run async events in a sequential order.
What is different between ‘blocking’ and ‘non-blocking’ with respect to how code is executed?
Blocking code ‘blocks’ the call stack —> while it’s running, nothing else can happen. Non-blocking code doesn’t stay on the call stack forever, allowing other things to run while it does work.