Master Flashcards

1
Q

What is Node.js, and how is it different from other server side technologies?

A

Node.js is an open-source, cross-platform, server-side JavaScript runtime environment.

Node.js is different from other server-side technologies in a few key ways:

–> Language: It uses Javascript as its programming language. this means that developers can use the same language for both front-end and back-end development, which allows for a streamlined development process and reduced learning curve for juniors.

–> Non-blocking I/O model: allows a single process to serve multiple requests at the same time. Makes it great for real-time data processing like chat or streaming services.

–> Package Management: Node.js comes with a built-in package manager called npm (Node Package Manager), which allows developers to easily install, manage, and share reusable packages of code.

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

How do you handle asynchronous programming in Node.js?

A

Asynchronous programming is typically handled by using callbacks, promises and/or async/await.

–> Callbacks: A callback is a function that is passed as an argument to another function and is called when that function completes its operation. Can lead to nested callbacks (callback hell).

// example 1
fs.readFile(‘file.txt’, UTF-8, function(err, data) {
if (err) throw err;
console.log(data);
});

–> Promises: A Promise represents the eventual completion or failure of an asynchronous operation and can be in one of three states: pending, fulfilled, or rejected. Promises make it easier to write asynchronous code that is more readable and less error-prone.

// example 2
const fs = require(‘fs’).promises;

fs.readFile(‘file.txt’)
.then(data => console.log(data))
.catch(err => console.error(err));

–> Async/Await: The async keyword is used to define a function as asynchronous, and the await keyword is used to wait for a Promise to resolve before proceeding with the next instruction.

// Example 3

const fs = require(‘fs’).promises;

async function readData() {
try {
const data = await fs.readFile(‘file.txt’);
console.log(data);
} catch (err) {
console.error(err);
}
}

readData();

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

What is an event loop?

A

The event loop is responsible for managing all the asynchronous and non-blocking operations in Node.js.

The event loop works by continually monitoring the call stack - The call stack is where functions are executed in a first-in, first-out (FIFO) order. When a function is called, it is added to the call stack, and when it returns, it is removed from the stack.

Overall, the event loop is a crucial component of Node.js, as it allows Node.js to handle multiple requests and connections simultaneously without blocking the execution of the program.

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

In the context of OOP, what is a trait?

A

a trait is a grouping of methods and properties that can be reused in different classes. Traits are a way to implement code reuse in OOP without creating a new class hierarchy. ties into the idea of code “composability”.

// Example

–> Mammal class
–> Human Class
–> Humanoid Class

Since both the human class and humanoid class would share similar “traits”, but the humanoid class can’t inherit the mammal class, we may opt to abstract some of the methods/properties into a trait that both humans and humanoids can access.

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

How do you go about designing a database? What things do you consider?

A

1.) identify the requirements of the database - understanding the data that needs to be stored, talking to stakeholders about what they expect to be stored, analyze

2.) Entity-relationship diagram - This is a conceptual model of the database. Identify the “objects” that the database will be holding and the relationships between them –> eg. Users, Products, Orders, Shipments. A User has many orders, and order has many products.

3.) Define the schema: This involves defining the tables, columns, and relationships between the tables. Each table should have a primary key, which is a unique identifier for each row in the table, and other columns should use corresponding data types –> DATE, VAR_CHAR, TEXT etc…

4.) Normalize the data - the process of cleaning up the data to minimize redundancy and improve data integrity. Breaking down the data into smaller, more manageable tables. Eg. instead of having the products information stored in the orders table, create a products table and reference the product id in the order table with a foreign key.

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

What does your ideal local environment look like? How would you set it up?

A

My ideal local environment setup would consist of:

–> MacOS operating system
–> Visual Studio Code for my text editor
–> Using Docker in a team setting with a Docker image that had Node, Postgres, Express, React on it. In a personal setting I would probably just run these locally.
–> NPM for package mgmt.
–> React debugger on my browser console
–> Mocha/chai testing framework installed as well.

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

What resources do you use to stay up to date with new technologies?

A

–> Reddit (r/webdev, laravel, learningprogramming, React, javascript)
–> medium
–> Dev.to
–> Twitter (sometimes)

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

How do you organize your coding projects?

A

1.) Create a root directory
2.) Use subdirectories to organize related files:

–> Client folder that holds views/templates, components, hooks, public assets like css or images.

–> Server folder that holds routes, .env, database scheme, seed file, queries.

2.) Use a consistent naming convention between files or follow framework best practices.

3.) Make sure to initialize git in the root directory.

4.) initialize npm and your package.json in both your client and server directories.

It also really depends on the framework you are working with - Something like Ruby on rails or Laravel would have you organize your code into Models, View, Controllers, Factories, Routes which would be a little different then how you would setup a Express project.

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

Can you explain the difference between callbacks, promises, and async/await?

A

Callbacks, Promises, and Async/Await are three different ways to handle asynchronous operations in JavaScript.

–> Callbacks: are functions passed to other functions, and are executed once an asynchronous operation is complete.

–> Promises: represent a value that is is not available yet, but may be in the future. A promise has three states: pending, fulfilled or rejected. Promises can be chained using the .then() and .catch() methods to handle success and failure cases.

–> Async/Await: Async functions return a Promise, and the await keyword can be used to pause the execution of the function until a Promise is resolved. Async/Await is typically easier to read as its written similarly to synchronous code.

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

What is the purpose of the package.json file?

A

A package.json file is very important to a node.js project because it handles:

1.) Dependancy Management - all the 3rd party libraries that your project uses.
2.) Project Configuration - version, description, license, development mode scripts.
3.) version control
4.) Publishing to npm registry.

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

How do you manage dependencies in a Node.js project?

A

The most popular way to manage dependencies in a Node.js project is by initializing the project with NPM (node package manager) which will create a package.json file in the root of your project.

Another option would be to use a similar dependancy manager like yarn, which has gained popularity over the years.

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

How do you handle errors in a Node.js application?

A

1.) using try/catch blocks in your code.
2.) Error-first callbacks - where the first argument of the callback function is an error object.
2.) Throw new Error - allows for a user defined exception that you can add to your functions to handle error states.

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

Can you explain the difference between the “require” and “import” statements in Node.js?

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

How do you use streams in Node.js, and what are some use cases for them?

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

How do you deploy a Node.js application to a production server?

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

What are some best practices for writing clean, maintainable Node.js code?

A
17
Q

What are some aspects of a framework like Express that you enjoy working with?

A
18
Q

What are some aspects of React that you enjoy working with?

A
19
Q

Can you explain how you would handle authentication and authorization in a Node.js application?

A
20
Q

How would you connect your database to a node application?

A
21
Q

Whats the difference between relational database and a noSql database?

A
22
Q

Describe the HTTP lifecycle.

A
23
Q

What does Asynchronous mean?

A
24
Q

Whats your strategy for project managing a web development project?

A

1.) Define project scope and requirements - understand what the client/stakeholders want.

2.) Plan your project - project plan, setting timelines, and determining milestones.

3.) Breakdown tasks - breakdown the project into smaller, more manageable tasks.

4.) Use a project management tool - Trello, Jira, Asana.

5.) Set deadlines

6.) Communication with stakeholders - ensure that you communicate regularly with stakeholders to keep them informed of progress and to address any concerns they may have.

7.) Testing and quality assurance - ensure that your web development work is of a high standard and meets the client’s requirements.

8.) Deploy the app and monitor for any issues.