Basics Flashcards

1
Q

Create Server

A

var http = require(‘http’)

http.createServer(function(req,resp){
resp.writehead(200,{content-type:’text/html’}
resp.write(‘blah’)
resp.end
}).listen(8080)

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

how to read url

A
var url = require(url)
http.createServer(function(req,resp){
resp.writehead(200,{content-type:'text/html'}
resp.write('blah')
var urlValue = url.parse(req.url)
resp.end
}).listen(8080)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to read files

A
var fs = require(fs)
use fs object to read, edit and delete files
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to raise events

A
var events = require('events')
var eventEmitter = new events.EventEmitter()
//subscribe
eventEmitter.on('som_event',( data)  => { } )
eventEmitter.emit('some random event')
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Node

A

Node is a runtime built using the open source Program called V8 Engine, to run Javascript outside the browser.
V8 itself is written in C++ and it is the same program which powers the Chrome Browser. Node Compile Javascript to low level Machine level instructions and runs it.

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

Some Commans=ds to run in the node command prompt

A

Global

process

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

How to export a property from a file in Node

A

module.export.age = 25

Exports a property named age, with a value 25 from the file

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

Export a new function named Add

A

module.exports.add = (one,two) => return one + two

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

What is nodemon?

A

something which listens to file changes and restarts Node automatically.Used only in Dev mode.

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

how to get all command line arguments passed to program

A

process.argv

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

Which plugin can be used to process command line arguments

A

yargs

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

Which framework is used to serve static files from node

A

express-static

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

Commonly used Express MiddleWares

A

body-parser : This is used to parse the body of requests which have payloads attached to them

cookie-parser: parses Cookie header and populate req.cookies with an object keyed by cookie names

express-session: creates a session middleware with the given options.

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

How to create an express server

A
var express = require("express")
var app = express()
app.get("/",(req,res) => {})
app.listen(8000)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to add middlewares in express

A
var express = require("express")
var app = express()
app.use(MIDDLEWARES)
app.get("/",(req,res) => {})
app.listen(8000)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

how to create router middleware

A
var express = require("express")
var app = express()
var router = express.Router()
router.get('/hello',(req,res) => { })
17
Q

how to serve static files from Express?

A
var express = require('express');
var app = express();

//To Serve static files from folders names Public and Images.

app. use(express.static(‘public’));
app. use(express.static(‘images’));

18
Q

Which middleware is used in Express to process form data

A
var bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({ extended: true })
19
Q

Which middleware is used in Express to process Multi- part form data

A
var multer = require('multer');
var upload = multer();
app.use(upload.array());
20
Q

How to set cookie on a request

A

var cookieParser = require(cookie-Parser”)

app. use(cookieParser())
router. get(“/sendCookie”, (req,res) => {
res. cookie(“name”,”Panji Mittai”).send(“cookie set”)

})
21
Q

Framework to do microservices in Nodejs

A

Moleculer