Wednesday, September 24, 2014

Node.js tips and modules

Several useful modules and tips for Node.js beginners.

  • Nodemon, monitor the source file change and reload it for you automatically.

typically, we have to stop the node process and restart it when we changed the code, this happened a lot during dev phase. nodemon is the tool to solve this pain.  remember to install it as a global module. (try upgrade node to latest version if installation failed)

image

  • sleep module. sometimes you want to simulate some CPU intensive operation. or to drain the V8 thread pool, you can try this module

without sleep, this simple code can sever 100 req/s at least. since no pressure on event loop and thraed pool.

image

by ab testing with 1000 req and 1000 concurrent connections. and Node.js use little CPU.

image 

if we put sleep for each response, it will be super slow. maybe 1request every 2 seconds.

image

  • express-generator , once you install this global module, you can call the express utility to generate the project layout. like the JADE views, styles, even the stylus support.
    image

image

  • jshint , the code quality check tools

image

Sunday, September 21, 2014

Chrome Develop Tools Tips -2

  • using monitorEvents like the Spy++ using in old days to monitor event triggered on an element

image

  • by pressing CTL+F, you can use element/css/xpath selector to select the right element.

image

image

  • in the timeline of network tab, you can sort by the latency that find which site’s DNS sucks (latency)

image

image

  • besides javascript breaks, you can setup DOM breaks.

image

wheneven this is one change, it will break and stop

image

Chrome Developer Tools Tips - 1

I've been using the Chrome developer tools always, just realized several tips.

  • Console.dir will list all the attributes or methods of an object.

image

  • we can use console.group to group logs.

image

  • $ $$ and $x selector, (return 1st object, colelction and by xpath), an example running on google.com homepage.

image

  • Using inspect method to highlight the dom element get selected

image

 
Locations of visitors to this page