Node.js Flashcards
What is Node.js?
Node.js is a program that allows JavaScript to be run outside of a web browser. Node.js is powered by V8; the same JavaScript engine in the Google Chrome 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?
read-eval-print loop
Also termed an interactive top-level 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 back end languages have you heard of?
Scripting Languages, these are interpreted on-the-fly
python, ruby (jit - just-in-time compilation), php, javascript (jit - 2008), perl, elixir, erlang
Memory Managed Languages - these languages are complied ahead of time, garbage collection
Java / Kotlin, Golang, C#, Haskell, Julia, F#, Fortran
Manual Memory Management - ahead of time compiled, low-level
C++, C, Swift, Rust, D, Zig
SQL - for databases
What is theprocessobject in a Node.js program?
The process object is a global that provides information about, and control over, the current Node.js process.
How do you access theprocessobject in a Node.js program?
As a global, it is always available to Node.js applications without using require(). It can also be explicitly accessed using require(): const process = require(‘process’);
What is the data type ofprocess.argvin Node.js?
The process.argv property returns an array (of strings) containing the command line arguments passed when the Node.js process was launched.
What is a JavaScript module?
A single .js file. A module is just a bit of code encapsulated in a file, and exported to another file. Modules focus on a single part of functionality and remain loosely coupled with other filed in an application. This is because there are no global or shared variables between modules, as they only communicate via the module.exports object. Any code that you want to be accessible in another file can be a module.
Node.js programmers strive to separate their code into modules that each provide a small chunk of functionality. The program is a result of all these modules working together in concert.
What values are passed into a Node.js module’s local scope?
exports, require, module, __filename, __dirname
Give two examples oftrulyglobal variables in a Node.js program.
Console, process, global
What is the purpose ofmodule.exportsin a Node.js module?
The main purpose of module.exports is to achieve modular programming. By module.exports, we can export functions, objects, and their references from one file and can use them in other files by importing them with the require() method. Exports is the object that is returned from the require() call.
Can achieve abstraction to separate business logic from other modules.
Easy to maintain and manage the code base in different modules.
Enforces separation of concerns.
How do you import functionality into a Node.js module from another Node.js module?
require(“./filename’)
It is important to prefix the file name with ./ which tells Node.js that we are importing a local module. When require imports the module, it returns an object with the function as its method.
What is a directory?
A directory is a file [system cataloging structure] which contains references to others files and directories.
What is a relative file path?
Path to a file from the current directory