Log4js

Log4js

Tips

  • By default, log4js level for default category is set to OFF, thus not outputting any logs. To turn on logging, level must be set other than OFF.
  • Levels: TRACE -> DEBUG -> INFO -> WARN -> ERROR -> FATAL
Read more
Using MongoDB in node.js

Using MongoDB in node.js

Ref

Concepts

What is MongoDB

  • A leading document, NoSQL database.
  • Highly available, scalable.
  • Flexible schema.

Document and scale-out

  • Instead of storing tablesof rows or columns like RDBMS, record in MongoDB is document based in BSON, which is a binary representation for JSON.
  • Document format makes data:
    • highly flexible
    • allowing varaitions in structure
    • allowing partial complete data
    • can embed one document in another
  • Based on scale-out architecture, a structure which enables many small machines to work together to create fast systems and handle huge amounts of data.
    • With it, MongoDB can scale.

BSON Example:

1
2
3
4
5
6
7
8
9
{
"_id": 1,
"name": {
"first": "Ada",
"last": "Lovelace"
},
"title": "The First Programmer",
"interests": ["mathematics", "programming"]
}

Glossary

  • Database: Container for collections.
  • Colletion: A group of documents. No schema enforced. But documents should be grouped for similar purpose.
  • Document: A set of key-value pairs. Dynamic schema.
  • Embedded Documents: Embedded documents are like join in SQL.

When to use

  • Big Data
  • Content Management and Delivery
  • Mobile and Social Infrastructure
  • Data Hub

Hands-on

Installation and running

  • Install MongoDB Community Server.
  • Go to <install_folder>/bin, run mongod.
    • You got: NonExistentPath: Data directory: D:\\data\\db\\ not found. Need to override this pre-configuration first.
  • mongod can run with command line parameters or read from a config file. Let’s just use command line first.
  • Run mongod --dbpath D:/mongodata/data --logpath D:/mongodata/log/mongod.log --port 27017. 27017 is default port.
  • Now the server is on.

MongoDB shell

MongoDB Compass

  • The official GUI tool for MongoDB.
Heroku

Heroku

Add proxy to heroku login

Read more
cookie, localStorage, sessionStorage

cookie, localStorage, sessionStorage

Comparison

Name Description Size Life
Cookie Small piece of text data filed by server and saved in browser and carried in every request. Mostly used for identifying user. 4KB User defined expiration. Default cleared on browser close.
localStorage Permanent storage for each domain. Not used in request. 5MB Permanent, unless cleared.
sessionStorage Transient storage for each domain. Not used in request. 5MB Available in current session. Cleared when tab or browser closed/refreshed.
Read more
CORS and withCredentials
Javascript this && Javascript Class VS Function
Pug

Pug

Ref

  1. Pug - getting started

What and why

  • Pug is an html template engine which simplies html coding.
  • Pug‘s predecessor is the well-known jade.
Read more