nodejs Flashcards
What is Node.js?
open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser
What can Node.js be used for?
executing javascript code outside of the web browser
What is a REPL?
read-eval-print loop and basically provides a programmer with an interactive programming environment
When was Node.js created?
May 27, 2009
What back end languages have you heard of?
node.js
What is a computer process?
instance of a computer program being executed by one or more threads
Roughly how many computer processes are running on your host operating system (Task Manager or Activity Monitor)?
529 processes, 2079` threads
Why should a full stack Web developer know that computer processes exist?
web dev is based on making multiple processes work together to form one application
What is the process object in a Node.js program?
global object that provides information about, and control over, the current Node.js process
How do you access the process object in a Node.js program?
process object or using require, i.e.,
the process object itself:
console.log(process)
or
assigning a variable to the require method of the object: const process = require('process') console.log(process)
What is the data type of process.argv in Node.js?
string
What is a JavaScript module?
a single js file, i.e., splitting JavaScript programs up into separate “modules” that can be imported when needed
What values are passed into a Node.js module’s local scope?
Variables local to the module will be private, because the module is wrapped in a function by Node.js (see module wrapper)
filename, dirname
Give two examples of truly global variables in a Node.js program.
exports, require
What is the purpose of module.exports in a Node.js module?
exports a file, i.e.,
module.exports.hello = () => { return ‘hello’; }
How do you import functionality into a Node.js module from another Node.js module?
using the require keyword, i.e.,
require(‘./name-of-that-is-using-module-exports’)
What is a directory?
collection of folders, files, etc
technically a “folder”
What is a relative file path?
local file path, i.e.,
./assets/images/hi.jpeg
linking to something on the same server
What is an absolute file path?
global file path, i.e.,
a domain (https://google.com)
usually has a protocol before like ‘http’, ‘https’. ‘ftp’, ‘file’
linking to something on a different server
What module does Node.js include for manipulating the file system?
fs/promises API which provides asynchronous file system methods that return promises
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