Node.js 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?
to build back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform
What is a REPL?
Read–eval–print loop
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
What back end languages have you heard of?
C#, Ruby, PHP, Java, JavaScript, SQL, and Python
What is the process object in a Node.js program?
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?
As a global you can just reference it. It can be explicitly accessed using require()
What is the data type of process.argv in Node.js?
array of strings
What is a JavaScript module?
A single .js file
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.
console, process
What is the purpose of module.exports in a Node.js module?
Module exports are the instruction that tells Node. js which bits of code (functions, objects, strings, etc.) to “export” from a given file so other files are allowed to access the exported code.
How do you import functionality into a Node.js module from another Node.js module?
use require function
const variable = require(./relativeFilePath )
What is a directory?
folder
What is a relative file path?
A path to a file based of the current location
What is an absolute file path?
The whole file path starting with a slash (the root)
What module does Node.js include for manipulating the file system?
fs module
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?
depends; the fs module itself has options to perform a given task async (usually denoted by callback functions and the lack of the sync keyword) or sync (usually denoted by the ‘sync’ keyword, i.e., syncaccess, writefilesync)
sync blocks the event loop saying perform this task first before anything else; makes the cpu wait
async is performant
aka The fs module is unique compared with other I/O modules (like net and http) in that it has both asynchronous and synchronous APIs - means that it provides a mechanism to perform blocking I/O