I am working with hyperledger-fabric on amazon managed blockchain. There I have written the chaincode with node.js. The problem is, the dependencies I'm using is not supported in amazon managed blockchain's peer. That's why I need to bundle my chaincode with the node modules. How can I do tha?
How Can I bundle a simple node.js application
266 views Asked by Khandker Tanvir Hasan At
1
Here are steps for bundling Node.js chaincode with external dependencies on Amazon Managed Blockchain Hyperledger Fabric 2.2 networks:
Why bundling is needed: Due to stringent security requirements, peer nodes in Amazon Managed Blockchain do not have access to the open internet. This means that peer nodes cannot download external dependencies at runtime when building/executing chaincode. If you suspect missing node_modules/ are responsible for errors in your chaincode, you can verify this by viewing Chaincode logs in Amazon CloudWatch, where reference to missing node_modules / dependencies will be clearly evident.
How to bundle dependencies First, navigate to the root directory of the chaincode you wish to deploy. Your package.json file should be present in this directory. From this directory, run
npm ito install node_modules. Then, move those node_modules to a new directory -- Example:Moving the dependencies to
lib/will allow you to package the installed NPM packages (dependencies) in the chaincode tar.gz file in the following steps. Because the node_modules are stored inlib/, the Node.js start script inpackage.jsonhas been modified slightly to tell the container environment that runs the chaincode where to find the dependencies at runtime:"start": "NODE_PATH=lib node <entrypoint filename>.js"With the node_modules bundled in
lib/and the start script for the chaincode modified to point to those node_modules, one can now package, install, approve and commit this chaincode as normal using the Chaincode Lifecycle commands.