Node.js

 
 
Node.js is a server-side software system designed for writing scalable Internet applications, notably web servers.
It is build on built on Chrome's JavaScript runtime. Programs are written on the server side in JavaScript, using event-driven, asynchronous I/O to minimize overhead and maximize scalability.

Node.js contains a built-in HTTP server library, making it possible to run a web server without the use of external software, such as Apache or Lighttpd, and allowing more control of how the web server works. Node.js enables web developers to create an entire web application in JavaScript, both server-side and client-side.

The latest Node.js version can be downloaded from: http://nodejs.org

Even numbered versions (0.4, 0.6, 0.8) are stable, and odd numbered versions (0.3, 0.5) are unstable. The stable releases are API-stable, which means that if you are using 0.8.1 and 0.8.2 comes out, you should be able to upgrade with no issues.







How to browserify node module bip32-utils



Information
Browserify will recursively analyze all the require() calls in your app in order to build a bundle you can serve up to the browser in a single <script> tag.

More information see:
http://browserify.org/
https://github.com/substack/node-browserify
https://github.com/bitcoinjs/bip32-utils

Operating system used
macOS 10.13. High Sierra

Software prerequisites
node.js


Procedure
  1. Install browserify.
    Type: npm install -g browserify

  2. Show all installed node modules and their versions.
    Type: npm -g ls --depth=0

    You should see:
    [email protected]

  3. Show browserify help.
    Type: browserify --help

  4. In the following example the node module "bip32-utils" will be browserified.
    More information about this module see: https://github.com/bitcoinjs/bip32-utils
    bip32-utils is a small set of utilities for use with BIP32 HD key nodes. It can be used in node.js or can be in the browser with browserify, which will be demonstrated below.

  5. Create a project directory.
    Type: mkdir ~/bip32-utils

  6. Install the node module bip32-utils locally inside this folder.
    Type: cd ~/bip32-utils
    Type: npm install bip32-utils

    The node module bip32-utils is now installed in folder ~/bip32-utils/node_modules
    I have installed bip32-utils-0.11.1

    To show all installed modules and their versions inside folder ~/bip32-utils/, type:
    cd ~/bip32-utils
    npm ls --depth=0

    It will show the error "UNMET PEER DEPENDENCY [email protected]^3.0.0"
    npm no longer installs peer dependencies so you need to install them manually.

    Type: npm install [email protected]^3.0.0

    Check if the error is fixed, type: npm ls --depth=0

  7. Create a file main.js inside this folder.
    Type: touch ~/bip32-utils/main.js

  8. Enter the following lines in file main.js

    module.exports = {
        bitcoin: require('bitcoinjs-lib'),
        bip32utils: require('bip32-utils')
    }


    Note:
    bip32-utils requires bitcoinjs-lib.
    The name bitcoin and bip32utils are arbitrary chosen, but it is important later when calling the module in the web page.

  9. To browserify the node module bip32-utils, the file main.js will be used as input. Browserify will go thru the main.js and will search all attached modules (= require()). Browserify will include the source of those "required" files in a new javascript file. The new javascript file can be given any name. In our example bip32_utils_browser.js. The bip32_utils_browser.js will contain the bip32-utils and bitcoinjs-lib sources.

    Type: browserify main.js -s Bip32JS > bip32_utils_browser.js

    Note:
    By using the flag -s you assign the global variable name "Bip32JS" to the module.

  10. The browserify can also transform the code.

    Using flag -d
    Type: browserify main.js -s Bip32JS -d > bip32_utils_browser.js

    -d means include the source map information for easier debugging in the output bip32_utils_browser.js. Source map information will help you for better error tracing during development proces, but it will make the output file much larger.

    To extract the source map information in a separate file:
    • Install node module exorcist: npm install -g exorcist
    • Type: browserify main.js -s Bip32JS -d | exorcist bip32_utils_browser.map.js > bip32_utils_browser.js
    • Now two files are created: bip32_utils_browser.js and bip32_utils_browser.map.js

  11. An example how to use the bip32_utils_browser.js inside a web page see bip32_utils_example.html.

  12. Copy the files bip32_utils_example.html and bip32_utils_browser.js to a webserver.
    Open a browser and access the bip32_utils_example.html file.