basic Flashcards

1
Q

package that needs to be added to create a nodejs server

A

const http = require(‘http’);

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

how do you create a node server once you have declare the correct package (module)

A

const server = http.createServer(requestListener)

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

what is a requestListener?

A

a function that will be executed for each incoming request. You pass it as a parameter to method server.createServer()

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

what is the structure of this requestListener?

A

a two parameter arrow function : (req, res) => { }

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

how does the server work after you set the requestListener function?

A

it does nothing unless you run server.listen(). This listen method starts a process in which nodes listen to the requests on the port you specified. Example used is server.listen(3000) that will listen on port 3000

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

what is the core definition of nodejs? what is it fundamentally. some equivalents in other platforms

A

a runtime. best homologo is aspnet. but any runtime framework (not only web) is

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

from the terminal point of view what does nodejs keeps doing while it has listeners registered?

A

he keeps its event loop to listen for requests. this is the core of nodejs. when there’s no listeners registered then there’s no need to be runing and node ends. in terminal you see it the cursor back ready fr you to open word.

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

main 3 properties of the req object

A

req.url, req.method, req.headers

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

famous header that web pages all have? what is its value?

A

Content-Type that usually is “text/html”

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

2 most used method in the response object

A

res.setHeader, res.write

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

how do we tell the runtime (node) that we are done writing the response?

A

res.end();

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

how do you return 200 or 302 or 500

A

res.statusCode = 302

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

what 302 means

A

status code for redirection

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

how do you write in a file

A

fs.writeTextSync(‘filename.txt’, “mnmnmn”);

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

how do you redirect

A

res.setHeader(‘Location’, ‘/’); res.statusCode = 302

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

how do you create the package.json

A

npm init and filling the information.

17
Q

what is the name of the field in the package json where you add the autorun configuration? y dentro de este? y then how you specify the app to run?

A

“scripts” y dentro de este “start”: “node app.js”

18
Q

how do you run your code from the autorun configuration?

A

npm start

19
Q

install nodemon in prod

A

npm install nodemon –save

20
Q

install nodemon in dev

A

npm install nodemon –save-dev

21
Q

install nodemon globally

A

npm install nodemon -g

22
Q

what is the name of folder created by nodejs when you add nodemon

A

node_modules

23
Q

when you install nodemon what is added to package. json? y si fuera installed solo para production?

A

“dev-dependencies”: {
“nodemod”: “^1.2.3”
}
“dependencies” : {

24
Q

how to make a modules update?

A

npm install

25
Q

what does package-lock.json do?

A

contains references to all the exact versions your project is using. When you publish your project then they can use this to run it against these package and not the latest versions

26
Q

convenience of deleting the node_package folder. who can readd it again and why?

A

if you finish working with a package you delete the node_module folder to save space, then since it is declared in the package.json file just running npm install it would get the latest versions again.

27
Q

what are core nodejs modules ?

A

you don’t have to install them. just require them. Examples would be the file-system module (“fs”), the path module (“path”) or the Http module (“http”)

28
Q

what are third party modules?

A

You need to install them, and require them. nstalled via npm install - you can add any kind of feature to your app via this way Example nodemon

29
Q

what is a global feature?

A

features like const or function.

30
Q

what do you need to change in package.json to allow nodemon work?

A

not “start”: “node app.js” anymore, but “start”: “nodemon app.js”

31
Q

why you don’t need to share your modules when you share your application?

A

because the other developer can run npm install and this will take from package.json and reinstall the latest versions. That way, you don’t need to share node_modules folder.

32
Q

what are block variables in the debugger?

A

variables in the caller of the function that is being evaluated. they are blocked waiting

33
Q

what is the advantage of adding a variable to the watch section in debugger

A

you can see it while also can close local or other sections

34
Q

how do you add a configuration file for debugging? what is its name? under what folder is created? what fields need to be added?

A

debug/Add Configuration. se llama launch.json. .vscode folder. “restart”:true; “runtimeExecutable”: “nodemon” and “console”: “integratedTerminal”

35
Q

does the debugger configured to re-start, and with nodemon find the package in the local node_modules?

A

no, you need to install it globally

36
Q

how do you export a function in nodejs?

A

module.exports = functionName

37
Q

ES6 way to declare a function in Javascript?

A

const functA = (req, res) => {};

38
Q

conventional folder name for your htmls? and for your routes files?

A

views and routes

39
Q

turn arrow function (req, res) => {} into an anonymous function

A

function(req, res) {}