Basics Flashcards

1
Q

What is the purpose of the package.json file in a Node.js project?

A

The package.json file holds metadata relevant to the project, including the project name, version, description, main entry point, scripts, and dependencies. It is essential for managing project dependencies and configuration.

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

What is the difference between readFile and readFileSync in Node.js?

A

readFile is asynchronous and non-blocking, meaning it doesn’t block the event loop while reading the file. It takes a callback function to handle the file content after reading. readFileSync, on the other hand, is synchronous and blocking, meaning it stops the execution of code until the file is fully read.

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

What is the role of the event loop in Node.js?

A

The event loop is the core of Node.js’s asynchronous programming model. It continuously checks the call stack to see if there’s any function that needs to be executed, allowing non-blocking I/O operations by offloading tasks to the operating system or threads.

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

How do you create a simple HTTP server in Node.js?

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

What does the require() function do in Node.js?

A

The require() function is used to import modules, JSON, or local files into a Node.js file. It allows you to include the functionality of external modules, which can be core modules, npm modules, or your own files.

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

What is Express.js in Node.js?

A

Express.js is a minimal and flexible Node.js web application framework that provides a robust set of features for web and mobile applications. It simplifies the process of building server-side applications, handling routing, and managing HTTP requests and responses.

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

How do the event loop, callbacks, non-blocking APIs, and Node.js’s single-threaded nature contribute to its efficiency?

A

Node.js is highly efficient due to its single-threaded, event-driven architecture. The event loop allows Node.js to handle multiple operations asynchronously without blocking the main thread. Callbacks and non-blocking APIs ensure that the program continues executing while waiting for operations like I/O to complete. This design enables Node.js to manage high levels of concurrency with minimal resource usage, making it ideal for scalable network applications.

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

Why does node handle concurrent requests so well compared to other languages?

A

NON BLOCKING I/O

It’s non blocking because it uses the event loop, which is basically a registry of things to be done, then tracking which things needs to be done next. This way things can happen in parallel.

This doesn’t mean node is faster, it’s not as good at doing CPU intensive things because it only uses one thread. By default, it doesn’t use all the resources on a computer.

Node is the only language that is like this by default.

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

Browser vs nodejs,

A

In browser, everything is always window. (alert() is actually window.alert()).

In nodejs, it’s global. You almost never use it just like you almost never use window, but things are like global.setTimeout().

There’s no DOM! No document, no visual aspect.

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

What is the process object?

A

The operating system provides the global process object. shows the data of the system your code is operating on.

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

What does this do in the package.json?

A

Where all the CLI’s lives. It says we want to create a new entry for the CLI called “note”, and it should run “index.js”

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

What is the hashbang?

A

In Node.js, the hashbang (or shebang) is used at the beginning of a script file to specify the path to the Node.js executable, allowing the script to be run directly from the command line without explicitly invoking node.

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