Node.js Flashcards

1
Q

what is Node.js?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what can Node.js be used for?

A

primarily used for non-blocking, event-driven servers, but was designed with real-time, push-based architectures in mind

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

what is a REPL?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

when was Node.js created?

A

2009 by Ryan Dahl

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What back end languages have you heard of?

A
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)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

** command-line basics **

what is a CLI?

A

command-line interface

process commands to a computer program in the form of lines of text

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

** command-line basics **

what is a GUI?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

** command-line basics **

give at least one use case for each of the commands listed

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what are the three virtues of a great programmer?

A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

what is a computer process?

A

the instance of a computer program that is being executed by one or many threads

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

roughly how many computer processes are running on your host operating system (task manager or activity monitor)?

A

100+

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

why should a full stack developer know that computer processes exist?

A

computer processes can help with learning about applications made of multiple components

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

what is the process object in a Node.js program?

A

the process object is a global that provides information about, and control over, the current Node.js process

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

how do you access the process object in a Node.js program?

A

process.argv

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

what is the data type of process.argv in Node.js

A

Object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

what is a JavaScript module?

A

a separate JS file with its own code that will be part of a main JS file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

what values are passed into a Node.js module’s local scope?

A

ID, exports, parent, filename, loaded, children, paths

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

give two examples of truly global variables in a Node.js program

A

clearImmediateFunction, console object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

what is the purpose of module.exports in a Node.js module?

A

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

20
Q

how do you import functionality into a Node.js module from another Node.js module?

A

Module.export

require(‘./jsFile);

21
Q

what is the JS event loop?

A

constantly running process that monitors both the callback queue and the call stack

22
Q

what is different between “blocking” and “non-blocking” with respect to how code is executed?

A

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

23
Q

what is a directory?

A

a file system cataloging structure which contains references to other computer files, and possibly other directories

24
Q

what is a relative file path

A

refers to the location that is relative to a current directory

-starts with ./, ../, etc.

25
Q

what is an absolute file path?

A

includes the complete location of the file or folder, including which drive it’s on

26
Q

what module does Node.js include for manipulating the file system?

A

fs module

27
Q

what method is available in the Node.js fs module for writing data to file?

A

fs.writeFile(file, data[,options], callback)

28
Q

are file operations using the fs module synchronous or asynchronous

A

asynchronous

29
Q

what is a client?

A

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

30
Q

what is a server?

A

piece of computer hardware or software (computer program) that provdies functionality for other programs or devices, called “clients”

31
Q

which http method does a browser issue to a web server when you visit a URL?

A

GET

32
Q

what is on the first line of an HTTP request message?

A

start-line

    • HTTP method (GET, PUT, POST)
    • request target
    • HTTP version
33
Q

what is on the first line of an HTTP response message?

A

start line/status line

    • protocol version (HTTP/1.1)
    • status code
    • status text
34
Q

what are HTTP headers?

A

HTTP headers let the client and the server pass additional information with an HTTP request or response

35
Q

is a body required for a valid HTTP response?

A

no, not all HTTP/responses have a body

36
Q

what is NPM?

A

provides hosting for software development and version control with the usage of git

npm consists of

  • website
  • command line interface(CLI)
  • the registry
37
Q

what is a package?

A

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

38
Q

how can you create a package.json with npm?

A

cd to the root directory

-npm init –yes

39
Q

what is a dependency and how do you add one to a package?

A

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
40
Q

what happens when you add a dependency to a package with npm?

A

you are installing/adding the dependency to your package.json file and generates a node_modules folder with the installed modules

41
Q

how do you add express to your package dependencies?

A

npm i express

42
Q

what express application method starts the server and binds it to a network port?

A

listen() method

43
Q

how do you mount a middleware with an Express application?

A

app.use(/filepath)

44
Q

which objects does an Express application pass to your middleware to manage the request/response lifecycle of the server?

A

request object, response object, (next middleware function in app’s request-response cycle?)

45
Q

what is the appropriate content-type header for HTTP messages that contain JSON in their bodies?

A

application/json

46
Q

what is the significance of an HTTP request’s method?

A

indicates the desired action to be performed for a given resource

47
Q

what does the express.json() middleware do and when would you need it?

A

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