Node.js Flashcards
What is Node.js?
- An asynchronous JavaScript runtime
- A program or set of libraries 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 any kind of automation that developers wish to perform
- It is primarily focused on creating simple, easy-to-build network clients and servers.
- Can write client application and server applications in Node
What is a REPL?
- Stands for “Read-Eval-Print-Loop”
- It is reads single user inputs, executes/evaluates them, and returns/prints the result to the user
When was Node.js created?
2009
What back end languages have you heard of?
- Python
- Ruby on Rails
- Java
- PHP
- C++
- C#
- SQL
- Perl
- Go
What is a computer process?
- The instance of a computer program that is being executed by one or many threads.
- It contains the program code and its activity.
- It is the actual execution of the computer program instructions.
- takes the program and runs it, starts asking for RAM
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
hundreds
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, so having at least a cursory awareness of computer processes is necessary
- NEED to know HTTP
- client process sends http request to
runtime
- when the program is executed
- language environment, how your program is executed by node.js
What is the process object in a Node.js program?
The process object is a global that provides information about, and control over, the current Node.js process. As a global, it is always available to Node.js applications without using require().
How do you access the process object in a Node.js program?
global process
What is the data type of process.argv in Node.js?
An array
process.argv (property)
- Returns an array containing the command line arguments passed when the Node.js process was launched.
- First element: process.execPath. (See process.argv0 if access to the original value of argv[0] is needed. )
- Second element: the path to the JavaScript file being executed.
- The remaining elements will be any additional command line arguments.
What are real world applications for using process.argv?
command line processes use own process.argv
modular programming
- breaking up into chunks and having smaller pieces of functionality
- a software design technique that emphasizes separating the functionality of a program into independent, interchangeable modules, such that each contains everything necessary to execute only one aspect of the desired functionality.
What is a JavaScript module?
a single .js file.
What values are passed into a Node.js module’s local scope?
\_\_dirname \_\_filename exports module require()
Give two examples of truly global variables in a Node.js program.
process
Class: Buffer
CommonJS
a project with the goal to establish conventions on the module ecosystem for JavaScript outside of the web browser. module specification is widely used today, in particular for server-side JavaScript programming with Node.js.
What is the purpose of module.exports in a Node.js module?
to store one module’s properties and methods on the module.exports to be transferred to another module
How do you import functionality into a Node.js module from another Node.js module?
require function
What is the JavaScript Event Loop?
The process in which JS monitors the stack and callback queue. If the stack is empty, it will push tasks (if any) from the task/callback queue onto the stack
What is different between “blocking” and “non-blocking” with respect to how code is executed?
blocking: code that is executed synchronously, code that blocks the call stack and prevents the browser from doing anything else until the process is finished
non-blocking: code that is executed asynchronously, still allows the browser to do its thing in between executing of this async code
What is a directory?
special type of file that holds information about more directories and files
What is a relative file path?
path to a specific file from another file (not at the root)
What is an absolute file path?
absolute path starts at the root of a file
What module does Node.js include for manipulating the file system?
fs module
fs.readFile(path[, options], callback)
- path | | | filename or file descriptor
- callback : err , data |
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?
both!