Wednesday, 25 April 2018

node

1. node concepts
  • http server + request router + request handler
  • use DI everywhere, pass router/handler as parameter to server
  • no 'return' is used, use async function, 'response' object is passed all the way to handler
  • in node, any async function accepts a callback as the last parameter
  • in node, any callback function accepts an error as the first parameter

2. even loop
  • timer: execute timer callbacks
  • pending callbacks: execute I/O callbacks
  • poll: incoming I/O events and callbacks

3. npm config file
  • ~/.npmrc

4. module.export and require
  • module.export return an object
  • require use the object
      module.exports = function(app, db) {};  // file1.js
      require('./app/routes')(app, {});               // file2.js

5. node/nvm commands
  • node -v
  • nvm --version
  • nvm ls-remote
  • nvm install x.x.x
  • nvm uninstall x.x.x
  • nvm use x.x.x
  • nvm use node                                   //switch to latest
  • nvm list
  • nvm install --lts                                //install latest
  • npm install -d                                   //--loglevel info
  • npm install jsonpath --save-dev      //save it in package.json
  • npm install -D jsonpath                   //-D is same as --save-dev
  • npm init                                           //new node app, generate package.json
  • node hello.js

6. node app config file
  • ./config by default
  • can be overwritten: process.env["NODE_CONFIG_DIR"] = __dirname + "/configDir/";

7. commonly lodash functions
  • .find()

8. returning everything as objects of functions

const retryCounter = () => {
    let retryCounter = 0
    const totalRetry = 10 //config.get('errorHandler.retryTotal')

    return {
        retryTotal: () => {
            return totalRetry
        },
        count: () => {
            return retryCounter
        },
        add: () => {
            retryCounter += 1
        }
    }
}

9. print stack trace
  • console.trace("Here I am!")

10. package-lock.json (normally more important than package.json, but)
  • package.json overrule the package-lock.json if package.json has been updated
  • 'npm install' sometimes does not update package-lock.json, better to use 'npm update' 
  • version in package.json
major.minor.patch
1.0.2
~1.0.2 means to install version 1.0.2 or the latest patch version such as 1.0.4
^1.0.2 means to install version 1.0.2 or the latest minor or patch version such as 1.1.0


11. dependencies vs devDependencies
  • dependencies is installed when using 'npm install' or 'npm install $package'
  • devDependencies is installed when using 'npm install' or 'npm install --save-dev $package'
  • dependencies is needed to run a package
  • devDependencies is need to develop a package



reference

Saturday, 7 April 2018

maven

1. lifecycle
  • clean
  • default
  • site
  • packaging of project: if no <packaging> value found, jar is used.

2. phase
  • clean (3)
  • default (21)
  • site (4)
  • 'mvn install' will execute all phases preceding 'install'

3. phase and plugin:goal
  • phase rely on plugin:goal to carryout the task
  • default binding between phase and goal exist:  test | surefire:test
  • 'mvn test' will execute default plugin/goal, i.e. 'mvn surefire:test'
  • plugin/goal can be executed outside of phase, e.g. 'mvn clean dependency:copy-dependencies package'
  • when execute maven you can specify 'phase' or 'goal'
  • if you specify 'phase', it will run all phases up till the specified phase, and it will run all goals attached to each phase
  • if you specify a 'goal', it will run all phases up till the phase for the goal, then it will run that goal
  • mvn-plugins-package-goal

4. mvn profile
  • use profile to customize build for different env
  • use 'mvn -P' option in command line to activate profile
  • profile can also be activated based on OS variable or jdk version

5. mvn command
  • mvn clean //remove target dir
  • mvn test //execute unit test
  • mvn install //install artifact to local repository
  • mvn install -DskipTests //skip test

6. maven surefire and failsafe plugin
  • surefire plugin is used in 'test' phase, it's designed to run unit tests and if any of the tests fail then it will fail the build immediately
  • surefire plugin has one goal: 'test'
  • failsafe plugin is used in 'integration-tests' and 'verify' phase, it's designed to run integration tests, and do not fail the build if there are test failures
  • failsafe plugin has two goals: 'integration-test' runs the integration tests of an application; 'verify' verifies that the integration tests of an application passed

7. parallel/fork
  • run junit in parallel two options

reference