Node.js Flashcards

1
Q

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

A

The process object is a global that provides information about, and control over, the current Node.js process. As a global, it is always available to Node.js applications without using require().

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

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

A

Just call process.

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

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

A

It returns an array containing the command line arguments when the Node.js process was launched. The first element will be process.execPath. The second element will be the path to the JS file being executed. The remaining elements will be any additional command line arguments.

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

What is process.execPath?

A

The process.execPath property returns the absolute pathname of the executable that started the Node.js process.

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

What is a JavaScript module?

A

In the Node.js module system, each file is treated as a separate module.

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

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

A

exports (object), require (function), module (object), __filename (string), __dirname (string)

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

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

A

console, process

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

What is the JS Event Loop?

A

Its job is to continuously watch both the stack and message queue. When the stack becomes empty, it checks the message queue to see if there are any messages waiting to be processed. If there are, it puts them into the call stack one at a time and executes them. Each message is associated with a function such as a callback or an event.

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

What is a directory?

A

is a special type of file that holds information about more directories and files

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

What is a relative file path?

A

a file relative to the current page

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

What is an absolute file path?

A

a full URL to a file

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

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

A

We include the fs module

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

Are file operations using the fs module synchronous or asynchronous?

A

asynchronous

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

What is JSON?

A

JSON is a text-based data format following JS object syntax, which was popularized by Douglas Crockford. JSON exists as a string.

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

What are serialization and deserialization?

A

Converting a string to a native object is called deserialization, while converting a native object to a string so it can be transmitted across the network is called serialization.

17
Q

Why are serialization and deserialization useful?

A

Useful when you want to transmit data across a network

18
Q

How to you serialize data into a JSON string using JavaScript?

A

JSON.stringify()

19
Q

How do you deserialize a JSON string using JavaScript?

A

JSON.parse()

20
Q

What is NPM?

A

npm is a package manager for the JS programming language. It’s a way to reuse code from other developers and also a way to share your code with them and it makes it easy to manage the different versions of code.

21
Q

What is a package?

A

A package in Node.js contains all the files you need for a module. Modules are JS libraries you can include in your project.
Video: Reusable codes == packages(or sometimes module)

A package is a directory with one or more files in it that also has a file called package.json with some metadata about this package.

22
Q

How can you create a package.json with npm?

A

Go to the directory where you want to create the package.json file and then run npm init –yes

23
Q

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

A

When you install an npm package using npm install , you are installing it as a dependency. The package is automatically listed in the package.json file, under the dependencies list.

The dependencies are the modules that the project relies on to function properly.

24
Q

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

A

The packages listed under the dependencies are required by your application in production.

25
Q

How do you add express to your package dependencies?

A

Use npm to install the express package from the npm registry.

26
Q

What Express application method starts the server and binds it to a network PORT?

A

listen

27
Q

How do you mount(attaching) a middleware with an Express application?

A

Bind application-level middleware to an instance of the app object by using the app.use() and app.method() functions, where METHOD is the http method of the request that the middleware function handles (such as GET, PUT, or POST) in lowercase.

28
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 and next middleware function

29
Q

What does express.static() return?

A

returns a middleware function

30
Q

What is the local __dirname variable in a Node.js module?

A

The directory name of the current module

31
Q

What does the join() method of Node’s path module do?

A

The path.join() method joins all given path segments together using the platform-specific separator as a delimiter, then normalizes the resulting path.

32
Q

(express) What is the significance of an HTTP request’s method?

A

It tells the server which action was requested by the client.

33
Q

What is Webpack?

A

Webpack is a static module bundler for modern JS applications. When web pack processes your application, it internally builds a dependency graph which maps every module your project needs and generates one or more bundles.

34
Q

How do you add a devDependency to a package?

A

npm install –save-dev

35
Q

What is an NPM script?

A

NPM scripts are written as usual JSON key-value pairs where the key is the name of the script and the value contains the script you want to execute.
Also, they are simply terminal commands.