Monday, November 4, 2013

Node and npm

Node is a new way of programming using javascript without running in a browser, it uses javascript libraries from google V8 javascript engine same as other language like C# using .net framework to support different functions. The node app can run as client or server app.

The important thing about Node is the application can only have a single thread. At first thought, that seems an extreme limitation as a developing language. But actually it is not once you change the view about multithread programming. The key is the event driven programming model using the callback methods. So when a method is called, it will not immediately return its result to caller, instead the method allows developers to provides one or few callback methods as the parameter to handle the result later. A major benefit is developers are forced to use asynchronous method invocation, the method call will return immediately without being blocked while waiting for the result. And once the result is finally available, it will be handled by the callbacks method automatically. This callback model simplifies the asynchronous programming model and helps developers to handle asynchronous naturally. The only drawback is it does not provide the callstack as synchronous request, which should be overcome by adding call history in the callback method object.

The node application can run on console with command line parameter of js file name
node appName.js

npm is one of node application, it manages the node apps as packages, and provides a generic way to manage the third party node libraries.

If a npm package is only download to use by node's require method, then download it locally.
If a npm package is used from command line console, then download it globally

A npm package includes the main js file invoked by node, it also include package.json for its configuration and dependent information.

The following link is a good tutorial to create a npm package
http://www.anupshinde.com/posts/how-to-create-nodejs-npm-package/

1 comment:

  1. Before we accept any writer, he/she passes a job interview and several tests. Do My College Homework

    ReplyDelete