Intro And NPM Flashcards

1
Q

Two things to do to run a server ?

A
  1. Create a server
  2. Start a server
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Http.createServer accepts what ?

A

A call back function with req and response options

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

What is the standard IP address of the local host ?

A

127.0.0.1

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

How can we see what options req method has ?

A

We can console log req parameter when we are creating a server. And we first create a server which takes a call back function this is where we can send back a response. And then we run the server by running listen method and this takes a couple of parameters like port number, host address and a call back function which you can use to console log server is running

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

What module do we use in default node to set up routing ?

A

We use url module

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

How do we implement the routing using http module ?

A

We save the req.url to a variable and then use a big if else statement to define routes for different requests

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

Where do we assign a variable to req.url and where do we use if else statements to implement routing ?

A

If the the create server call back function

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

How do you set a http status code ? Like 404

A

In the pure NodeJS example, you can use res.writeHead() method to send back a response. It will look like this
res.writeHead(404)

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

How do you set content type in the header ?

A

You can send it with res.writeaHead(404, {
‘content-type’:’text/html/})
Content type is written as the second parameter in writeHead()

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

How do you write Jason code ?

A

Both key value pairs should be strings separated by : inside curly bases. Json looks a lot like objects

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

Give an example of receiving data in a Json file and then reading it. In this case console log it.

A

fs.readFile(‘./dev/text.txt’, ‘utf-8’, (err, data) =>{
const productData = JSON.parsedata(data)
console.log(productData)})

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

How do you know which code will be executed once only ?

A

All the top level code gets executed once only

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

When to use the sync version ? In this case give an example of fs.readFileSync

A

Whenever the code is supposed to be used once is when we can use sync version because sync version only gets executed once and same goes for the top level code.

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

Give an example of adding place holders in HTML file

A

<h1>{%PRODUCTNAME%}<h1></h1>
</h1>

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

When does readFileSync return a buffer ?

A

It returns a buffer when you don’t specify an encoding

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

Most popular array methods ?

A

MAP, Filter and Reduce

17
Q

Describe three key characteristics of the map function

A
  1. It runs a function on every element of an array
  2. It does not executed a function on elements without values
  3. The JavaScript map method does not change the original array
18
Q

When to use Map method ?

A

It is required whenever we went to call a function for every element of an array

19
Q

What happens if you don’t have curly braces in an arrow function ?

A

The function returns immediately.

20
Q

How do we define prettier configuration ?

A

We can create a file . prettierrc