0% found this document useful (0 votes)
3 views10 pages

COMP 1537 - Week 14 - CRUD, Logging, Dynamic Code Loading (2)

The document discusses key concepts in JavaScript including the differences between null and undefined, the use of strict mode, and dynamic loading of JavaScript. It also covers CRUD operations, emphasizing Responsibility-Driven Design, and highlights the importance of logging in applications, suggesting various logging modules and their features. Finally, it addresses the significance of logging HTTP requests for web applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views10 pages

COMP 1537 - Week 14 - CRUD, Logging, Dynamic Code Loading (2)

The document discusses key concepts in JavaScript including the differences between null and undefined, the use of strict mode, and dynamic loading of JavaScript. It also covers CRUD operations, emphasizing Responsibility-Driven Design, and highlights the importance of logging in applications, suggesting various logging modules and their features. Finally, it addresses the significance of logging HTTP requests for web applications.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

COMP 1537

CRUD, Logging, Dynamic Code Loading

Copyright Ⓒ 2022, Arron Ferguson


NULL VS. UNDEFINED (1/2)

 Undefined
 A variable has been declared, but no value/type has been assigned or;
 When you look up a non-existent property on an object

 Null
 Is an assigned value for an object
 No object yet defined for the object reference
NULL VS. UNDEFINED (2/2)
WHAT IS STRICT MODE IN JS?

 Strict mode was introduced in ECMAScript 5


 You can specify it at the top of your file
 In which case all of your script must adhere to the strict rules
 You can specify it at the function level (only function is strict then)
 Usage: 'use strict';
 What does it do? It enforces more strict rules:
 Variables must be declared before usage
 Can’t assign if no setter, not allow arguments duplicate name
 Can’t specify duplicate property names
DYNAMIC LOADING OF JS

 Can do functions, classes (if not using jQuery)


 The problem (jQuery):
 Event is signalled when a JS file is loaded
 But not turned into executable code!
 Short scripts work, but if longer, you may need to setInterval
 Which is a horrible hack!

 Can be useful for certain circumstances


CRUD (1/2)

 Create, Read, Update, Delete


 You’ve already done CR
 These are considered the “four basic operations of persistent
storage
 Sometimes also called, “viewing, searching, and changing”
 This is something that you can do with any type of data store
 A relational server (e.g., MySQL)
 Or non-relational (e.g., MongoDB)
CRUD (2/2)

 New(-ish) concept: Responsibility-Driven Design (RDD)


 Each module responsible for its own data
 And being as independent as possible

 Case study: the CRUD examples for this course


Let’s look at the code!
 Observations of these two examples (MySQL & MongoDB)
 Both have identical client code on the client
 Only the DB calls in the server code are different
 This could further be refactored to use classes or external functions – that
further promote the RDD methodology
LOGGING (1/3)

 Up until now we’ve just used console.log()


 This is okay for in class demos/assignments/labs
 But not good for when we deploy!

 Why do we “log” stuff?


 Save information about flow of runtime code
 Errors, warnings, failure to connect to other resources
 Web analytics
 Path requests, logins/logouts, session data, transactions, etc.
LOGGING (2/3)

 What logger modules should we consider?


 For errors/warnings, there are at least three:
 ‘winston’, ‘bunyan’, ‘log4js’
 Features that you’ll want to consider:
 Multiple logging levels (e.g., alert, warning, etc.)
 Multiple data stores (e.g., text file, DB, in-memory data structure stores –
such as Redis)
 Formatting of data
 Fixed queuing of data (i.e., stale data deleted)
LOGGING (3/3)

 For HTTP requests, ‘morgan’, which has the following features:


 formatting – including common formats such as Standard Apache
common log output
 Output to file – including rotating file stream
 Choosing logging based on:
 HTTP method, URL, response time, remote IP address, referrer, and various
HTTP header info
 Logging to file and later using in an analytics server is an
important part of any web app’s livelihood and longevity!

You might also like