Node Flashcards

1
Q

What is Node.JS?

A

A program that allows JavaScript to be run outside of a web 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

Commonly used to build back ends for Web Applications, command-line programs, or other automation software 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 a ‘language shell’

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 —> created by Ryan Dahl

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

What backend languages have you heard of?

A

Python, Ruby, Java, PHP, C, C++, c# (.net), JavaScript (&Node)

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 that provides information 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

What is a ‘process’?

A

Any one program that your computer is running at a given time

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

When you execute a file with node, you start a…

A

Process!

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

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

A

It’s globally available, so you can just type ‘process’ (although it also can be required in)

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

What data type does process.argv return in node.JS?

A

It returns an array containing command line args passed in when the process was launched

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

What will process.argv[0] be?

A

The path to node’s executionable file

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

What will process.argv[1] be?

A

The path to the JavaScript file being executed

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

What will process.argv[2] onwards be?

A

Any command line arguments

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

Every index in the argv array always is… (data type)

A

A string

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

What is a JavaScript module?

A

A module is a single .JS file.

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

All modules are wrapped in a…

A

Function

17
Q

What values are passed into a Node.JS module’s local scope via the wrapping function?

A

exports, require, module, __filename, __dirname

18
Q

Give two example of truly global variables in a Node.JS program.

A

Process & console objects (global, setTimeout, setInterval)

19
Q

What determines what is returned by .require(‘file-path’)?

A

Whatever is stored in the module.exports variable in the file specified.

20
Q

Will variables between files collide?

A

No —> because each file is wrapped in a function, they have their own unique scope

21
Q

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

A

It allows you to export code out from one module

22
Q

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

A
  1. Set module.exports = ‘what-to-export’
  2. Use the require keyword with the file path passed in as the argument
23
Q

What is the JavaScript Event Loop?

A

It allows JavaScript to run async events in a sequential order.

24
Q

What is different between ‘blocking’ and ‘non-blocking’ with respect to how code is executed?

A

Blocking code ‘blocks’ the call stack —> while it’s running, nothing else can happen. Non-blocking code doesn’t stay on the call stack forever, allowing other things to run while it does work.

25
Q

What does ‘single-threaded’ mean?

A

It can only run one thing at a time

26
Q

What is a directory?

A

A unique type of file that contains travel information to access files or other directories

27
Q

What is a relative file path?

A

The path to a file from where you are currently at

28
Q

What is an absolute file path?

A

The path to a file from the root directory

29
Q

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

A

The File system (fs) module

30
Q

The require function always takes what data type?

A

String! Either a file path for a file OR a module name for a module

31
Q

When using an absolute file path, instead of using a hard-coded path you can use…

A

The path module —> path.join(argument1, argument2)

32
Q

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

A

fs.writeFile( )

33
Q

Are file operations using the fs module synchronous or asynchronous?

A

Depends on the operation! Typically asynchronous. Tbh ignore the synchronous ones.

34
Q

What is npm?

A

The worlds largest software registry. Three components: website, CLI, and registry.

No longer called node package module —> used for more than just node.

35
Q

What is a package in npm?

A

Reusable bits of code —> a directory with one or more files in it with a package.json file

36
Q

How can you create a package.json with npm?

A

Run the command ‘npm init’ at the root directory of the package.

Adding —yes auto-fills the package.json file

37
Q

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

A

It’s a library (another package) your project (your package) requires to work properly. Using npm install ‘package’ will install the package as a dependency.

38
Q

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

A

That dependency is added to the node_modules folder along with all files related to that package in addition to all of its dependencies. It also adds and it under dependencies in package.json