Node.js 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
  • it is used to build scalable network applications
  • it is also 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

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

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

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

A

The process object is a global that allows access to, and control over, the current Node.js process

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

How do you access the process object 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
7
Q

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

A

The process.argv property returns an array 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
8
Q

What is a JavaScript module?

A

-a single .js file that contains everything necessary to execute only one aspect of the desired functionality

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

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

A

process object, timer functions

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

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

A

-lets you carry forth (“export”) the code you need (functions, objects, strings, etc) onto other modules so they can be accessed there, too

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

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

A

-use the “require” keyword at the top of the file, with the argument being the code that you want to import

const add = require(‘./add’);

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

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

A

fs module

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

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

A

fs.writeFile

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

Are file operations using the fs module synchronous or asynchronous?

A

there are sync and async versions for all methods

  • asynchronous examples: fs.writeFile & fs.readFile
  • synchronous examples: fs.writeFileSync & fs.readFileSync
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are middlewares in Node.js?

A
  • middlewares are functions used in connecting a bunch of isolated systems to interact and perform certain tasks
  • ex: middleware is the wire that connects a light bulb and a switch