Node.js Flashcards
what is Node.js?
a cross-platform JavaScript runtime environment that allows developers to build server-side and network applications with JavaScript
Node.js is a way to execute JS outside of the browser environment
what can Node.js be used for?
primarily used for non-blocking, event-driven servers, but was designed with real-time, push-based architectures in mind
what is a REPL?
Read-Eval-Print-Loop (REPL)
REPL is a 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 by Ryan Dahl
What back end languages have you heard of?
Ruby (scripting) Php (scripting) Java (compiled) c## (compiled) Python (scripting) C (compiled) C++ (compiled) Swift (compiled/scripting) Objective-c (compiled) Javascript (script) Perl (scripting) Go (compiled) scripting/interpreted language is parsed and then some predefined functionality is executed (by a program called an interpreter) Compiled language is written one way, but then converted into something that a machine can already understand (by a program called a compiler)
** command-line basics **
what is a CLI?
command-line interface
process commands to a computer program in the form of lines of text
** command-line basics **
what is a GUI?
graphical user interface
a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation, instead of text-based user interfaces, typed command labels or text navigations
** command-line basics **
give at least one use case for each of the commands listed
man - reference to the online reference manuals
cat - concatenate files and print on the standard output
ls - list directory contents
pwd - print name of current/working directory
echo - display a line of text
touch - change file timestamps
mkdir - make directories
mv - move (rename) files
rm - remove files or directories
cp - copy files and directories
what are the three virtues of a great programmer?
Laziness: the quality that makes you go to great effort to reduce overall energy expenditure. It makes you write labor-saving programs that other people will find useful and document what you wrote so you don’t have to answer so many questions about it
Impatience: the anger you feel when the computer is being lazy. This makes you write programs that don’t just react to your needs, but actually anticipate them. Or at least pretend to.
Hubris: the quality that makes you write (and maintain) programs that other people won’t want to say bad things about
what is a computer process?
the instance of a computer program that is being executed by one or many threads
roughly how many computer processes are running on your host operating system (task manager or activity monitor)?
100+
why should a full stack developer know that computer processes exist?
computer processes can help with learning about applications made of multiple components
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
how do you access the process object in a Node.js program?
process.argv
what is the data type of process.argv in Node.js
Object
what is a JavaScript module?
a separate JS file with its own code that will be part of a main JS file
what values are passed into a Node.js module’s local scope?
ID, exports, parent, filename, loaded, children, paths
give two examples of truly global variables in a Node.js program
clearImmediateFunction, console object
what is the purpose of module.exports in a Node.js module?
module exports are the instructions that tell Node.js which bits of code to export from a given file so that other files are allowed to access the exported code
how do you import functionality into a Node.js module from another Node.js module?
Module.export
require(‘./jsFile);
what is the JS event loop?
constantly running process that monitors both the callback queue and the call stack
what is different between “blocking” and “non-blocking” with respect to how code is executed?
blocking is when the execution of additional JS in the Node.js process must wait until a non-JS operation completes.
something is blocking as long as it is on the call stack
-executes synchronously
non-blocking - executes asynchronously
what is a directory?
a file system cataloging structure which contains references to other computer files, and possibly other directories
what is a relative file path
refers to the location that is relative to a current directory
-starts with ./, ../, etc.
what is an absolute file path?
includes the complete location of the file or folder, including which drive it’s on
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 file?
fs.writeFile(file, data[,options], callback)
are file operations using the fs module synchronous or asynchronous
asynchronous
what is a client?
a piece of computer hardware or software that accesses a service made available by a server as part of the client-server model of computer networks
- phone, laptop, desktop
what is a server?
piece of computer hardware or software (computer program) that provdies functionality for other programs or devices, called “clients”
which http method does a browser issue to a web server when you visit a URL?
GET
what is on the first line of an HTTP request message?
start-line
- HTTP method (GET, PUT, POST)
- request target
- HTTP version
what is on the first line of an HTTP response message?
start line/status line
- protocol version (HTTP/1.1)
- status code
- status text
what are HTTP headers?
HTTP headers let the client and the server pass additional information with an HTTP request or response
is a body required for a valid HTTP response?
no, not all HTTP/responses have a body
what is NPM?
provides hosting for software development and version control with the usage of git
npm consists of
- website
- command line interface(CLI)
- the registry
what is a package?
a package is a file or directory that is described by a package.json file
-package must contain a package.json file in order to be published to the npm registry
how can you create a package.json with npm?
cd to the root directory
-npm init –yes
what is a dependency and how do you add one to a package?
dependency - package required by your application in production
- you can add dependencies to a package.json file from the command line or by manually editing the package.json file
- npm install from command line
- add attribute called dependencies to manually edit
what happens when you add a dependency to a package with npm?
you are installing/adding the dependency to your package.json file and generates a node_modules folder with the installed modules
how do you add express to your package dependencies?
npm i express
what express application method starts the server and binds it to a network port?
listen() method
how do you mount a middleware with an Express application?
app.use(/filepath)
which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?
request object, response object, (next middleware function in app’s request-response cycle?)
what is the appropriate content-type header for HTTP messages that contain JSON in their bodies?
application/json
what is the significance of an HTTP request’s method?
indicates the desired action to be performed for a given resource
what does the express.json() middleware do and when would you need it?
it is a built-in middleware function in Express. it parases incoming requests with JSON payloads and is based on body-parses
– use it only when you need to