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

back ends for Web applications, command-line programs, or any kind of automation that developers wish to perform.

building servers or backends for web applications

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

a simple interactive computer programming environment that takes single user inputs, executes them, and returns the result to the use - similar to a console.log

An example of a repl is the inspect tools.
A read–eval–print loop (REPL), also termed an interactive toplevel or language shell, 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

Python, C++, C#, Java, Ruby, PHP, Perl

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

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

A
  • a global variable that gives info about the current node.js process

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

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

A
  • same way you would any object ?
  • through node in the terminal
  • through node in the terminal executing js file with a console.log of the object/properties
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');

process keyword
Process is a global object so you can just reference it - console.log(process)

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

What is the data type of process.argv in Node.js?

A
  • an array of strings

This property returns an array containing the arguments passed to the process when run it in the command line

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

What is a JavaScript module?

A
a way of breaking javascript code into multiple files
their scope is module scope (they each have their own local scope)

A JavaScript module is a single JavaScript file

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

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

A

exports, require, module, __filename, __dirname

way loads modules, loads the raw string from the file & wraps it in in a wrapper & provides a unique value to the module with those 5 things

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

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

A

console
process
setTimeOut
setInterval

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

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

A
helps to share functions or variables between files.
- insures that the code in the module is able to be seen & accessed (connected to) by other modules in the application
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

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

A
module.exports
var variable = require('path to module/module name')
imports / export keywords

Module.export
require(‘./jsFile);

using the require function when you pass in a string of the ID or the path of the module you want to import

By calling the require function and passing relative path as its argument.

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

What is the JavaScript Event Loop?

A

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

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

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

A

A blocking assignment takes effect immediately it is processed. A nonblocking assignment takes place at the end of processing the current “time delta”. occupying the call stack.

blocking functions execute in a series whereas non-blocking functions execute concurrently.

blocking is when there is code that is slow on the call stack. this becomes an issue because blocking that stack means the browser can’t do anything while it waits for everything to run

blocking methods execute synchronously
non-blocking methods execute asynchronously

if there’s a code running, no other code can be running
blocking is anything that just sits on the call stack until it is complete
non-blocking is something that is deferred to the task queue that waits to be executed

“blocking” means script that is executed on the stack, It is “blocking” as long as it is on the stack. It is “non-blocking” when it’s not on the stack

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

What is a directory?

A

A special type of file whose whole job is to point to other files… a folder.
A directory is a file system that allows a user to group files together.
a directory is a file system cataloging structure which contains references to other computer files, and possibly other directories
v.

17
Q

What is a relative file path?

A

a relative file path is a path to file from the current directory.
a shorthand for a path within the same root directory
./dir
../parentdir
filename or dir

18
Q

What is an absolute file path?

A

the full path on the system, relative to root
includes the complete location of the file or folder,
an absolute file path is path from a systems root directory.

19
Q

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

A

The fs module (file system)

20
Q

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

A

fs.writeFile( ) method

writeFile

21
Q

Are file operations using the fs module synchronous or asynchronous?

A

asynchronous
asynchronous by default
if it says Sync at the end of the method then it’s synchronous