w2 Flashcards
purpose of MEAN
purpose is to use only JS to cover diff parts of applications
Advantage of MEAN
- single language throughout app
2.supports MVC architecture
- Data marshalling using JSON objects- transforming the memory representation of an object into another format, which is suitable for storage
Node.js
For browser
two-way comm b/w browser and server
JS- event driven language meaning?
- event-driven language- register code to events, code executed when event is executed- allows async programming -single thread aka event loop - when there is event created sent to event queue - sends task to event handler
Why node.js?
Node.js eliminates the waiting and continues with the next request. Node.js runs single-threaded, non-blocking, asynchronously programming, which is very memory efficient.
node.js syntax, data types?
Similar to front end JS
Six data types that are primitives:
Boolean Null Undefined Number String Symbol (new in ECMAScript 2015)
and Object
What is JS primary design flaw?
design flaws is the sharing of a single global namespace
Built-in modules Node.js
Node.js has a set of built-in modules that can be used without further installation
to export?
module.exports = Student;
class name
to import?
To import a package, you have to use the required keyword
define properties of appplication in node.js?
package.json->specify the version of your current release, the name of your application, and the main application file.
how to create new package.json file?
npm init
express?
added in package.json as dependency
in node_modules file too
HTTP ?
HTTP is the abbreviation of “HyperText Transfer Protocol”.
The HTTP server is the program that serves data to clients using the HTTP protocol.
HTTP works?
client sends request to server
server accepts the request and generates a response using its local database or files
the server sends back its response to the client
the client’s browser displays/renders the response
What is the HTTP.createServer() method?
The http.createServer() method turns your computer into an HTTP server by creating a HTTP Server object.
What can the HTTP.createServer() method do?
The HTTP Server object can listen to ports on your computer and execute a function, a request listener, each time a request is made.
createServer method?
requires a callback method (i.e. requestListener) as an input parameter
with each new request, the callback method will be invoked and provided with two parameters: request and response
Request object?
using the request object, you can get details about the coming request such as the method, URL, headers, and body of the request
Response object?
the response object contains many useful methods for sending data back to the client
res.writeHead()?
The argument of the res.writeHead() method is the status code, 200 means that all is OK, 404 is page not found
fs Node.js?
fs: the Node.js file system module allows you to work with the file system on your computer.
fs callback?
The callback is passed two arguments (err, data), where data is the contents of the file
Query string?
Is the part of a URL containing data that does not fit conveniently into a hierarchical path structure. For example:
http://example.com/over/there?name=Tim&age=20
starts with a question mark character (?)
Parameters are key-value pairs that can appear inside the URL path
Query string appears after the path (if any)
multiple query parameters are separated by the ampersand, “&”
How to split the query string into readable parts in Node.js?
using a function called ‘parse’, which is part of the ‘url’ module
‘searchParams’ returns an object representing the query parameters of the URL.
use the 'get' to extract the value of a given key
URL routing
changing file when pathname changes
http.createServer(function (request, response) {
//….
}
If a server wants to respond to a client’s request by a string, it has to use:
response.write() method
https://monash.edu:8900/fit/fit2095/?q=2&mark=10
Identify the following:
The query string The protocol The port number The pathname The server address
The query string- ?q=2&mark=10
The protocol- https://
The port number- 8900
The pathname- /fit/fit2095/
The server address- monash.edu
string to int?
int to string?
parseInt
.toString()