Node.js Flashcards
What is Node.js?
Node.js is a program that allows JavaScript to be run outside of a web browser.
What can Node.js be used for?
It is commonly used to build back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform.
What is a REPL?
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; a program written in a REPL environment is executed piecewise.
When was Node.js created?
May 27, 2009
What is the process object in a Node.js program?
Is a global variable that provides information about, and control over, the current Node.js process.
The process object is an instance of EventEmitter.
How do you access the process object in a Node.js program?
Call it as you would any other object in JS, it’s global
What is the data type of process.argv in Node.js?
array or strings
What does proces.argv do?
The process.argv property returns an array containing the command line arguments passed when the Node.js process was launched.
$ node process-args.js one two=three four
0: /usr/local/bin/node
1: /Users/mjr/work/node/process-args.js
2: one
3: two=three
4: four
What is a JavaScript module?
each separate js file
What values are passed into a Node.js module’s local scope?
(function(exports, require, module, __filename, __dirname) {
// Module code actually lives in here
});
Give two examples of truly global variables in a Node.js program.
console
process
What is the purpose of module.exports in a Node.js module?
Makes things available to other modules in your node. js program
How do you import functionality into a Node.js module from another Node.js module?
call the require function, pass in a relative path, and assign its return value to a variable
What is the JavaScript Event Loop?
The event loop looks at the stack and the task queue. I the stack is empty, it pushed it from the task queue to the stack, which effectively runs it.
What is different between “blocking” and “non-blocking” with respect to how code is executed?
blocking code is occupying the call stack.
What is a directory?
A file that lists other files and directories.
What is a relative file path?
a path to a file from where you are currently
What is an absolute file path?
starts from the root of the file system (starts with a slash)
What module does Node.js include for manipulating the file system?
fs
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?
asynchronous
What is NPM?
Node packaging manager
npm is the world’s largest software registry. A way for you to reuse code from other developers and for you to share code with them
npm consists of three distinct components:
the website
the Command Line Interface (CLI)
the registry (database of info about packages that people are sharing)
What is a package?
Bits of reusable code (also sometimes called modules). A package is a directory with one of more files in it that also has a file called package.json with some metadata about this package.
How can you create a package.json with npm?
- On the command line, navigate to the root directory of your package.
cd /path-to-package
- Run the following command:
npm init –yes