Node.js Flashcards

1
Q

What is Node.js?

A

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.

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

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

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

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

When was Node.js created?

A

May 27, 2009

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

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

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

What is theprocessobject 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
7
Q

How do you access theprocessobject in a Node.js program?

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

What is the data type ofprocess.argvin Node.js?

A

The process.argv property returns an array (of strings) containing the command line arguments passed when the Node.js process was launched.

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

What is a JavaScript module?

A
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.

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

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

Give two examples oftrulyglobal variables in a Node.js program.

A

Console, process, global

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

What is the purpose ofmodule.exportsin a Node.js module?

A

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

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.

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

What is a directory?

A

A directory is a file [system cataloging structure] which contains references to others files and directories.

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

What is a relative file path?

A

Path to a file from the current directory

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

What is an absolute file path?

A

Path to a file from the root of the file system, starts with a ‘/‘

17
Q

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

A

fs module (in-built File System module)

18
Q

What method is available in the Node.jsfsmodule for writing data to a file?

A

fs.writeFile

19
Q

Are file operations using thefsmodule synchronous or asynchronous?

A

There are both synchronous and asynchronous methods.

All asynchronous methods can perform synchronously by appending “Sync” to the function name. [e.g. fs.readFileSync() vs fs.readFile()]