The Node.js Azure Function Generator Guide
Overview
The Node.js Azure Function generator lets you set up and deploy an OpenLegacy service running on Node.js in the Azure Function serverless environment. The service enables you to expose APIs to several remote data source types, including Oracle DB, SQL Server db, CICS-COBOL, VSAM-CICS, IMS-PL1, IMS-COBOL, Sybase DB, and more.
At the end of this unit, you will learn to:
- First, generate a Node.js Azure Function service from an OpenLegacy Hub project.
- Build the service as a Node.js Azure Function project.
- Test the new Node.js Azure Function project locally.
- Finally, deploy the project to Azure Function.
Prerequisites
Satisfy the following prerequisites:
- Install NPM v6 or later.
- Install Node.js v12 or later,
- Install the Azure Function Command Line
- Install the Azure Functions Core Tools
- Create a writable Azure account.
- Have at your disposal the credentials of an OpenLegacy Jfrog Artifactory user with permissions to the ol-npm-native repositories.
Step 1: Generate an Azure Function service
First, generate a service using an OL Hub project and the Azure Function generator; see the ol generate command reference topic to learn more about service generation.
Currently (Jan 2022), the Node.js Azure Function service supports modules with the following connectors:
- oracle-db
- sqlserver-db
- mf-cics-cobol
- vsam-cics
- mf-ims-pl1
- mf-ims-cobol
- sybase-db
- ibm-mq-cobol
- ibm-mq-pcml
- as400-cobol
- as400-pcml
> ol generate --project "your_project_name" --generator azure-nodejs-function
$ ol generate --project "your_project_name" --generator azure-nodejs-function
The generated service folder is created. The folder is carrying the project name.
Step 2: Build the Node.js AWS service
First, build from the generated service a Node.js application.
Each deployable application consists of a native core library and a wrapper. The core library is dedicated to a specific remote data source, and the wrapper integrates the core library to the Node.js environment.
During the build, NPM pulls the Node.js core-native library wrapper from the OpenLegacy artifactory.
Install the ol-npm-native package using the npm install command:
> npm install
$ npm install
The node_modules directory containing the core-native library wrappers is created in your service directory.
Step 3: Test the Node.js Azure Function Project
After successfully building the Node.js application, you can test how it handles requests before deploying it to Azure Function.
-
Copy the contents of the in.json file used to test the asset with the ol test asset command when you created the original module.
-
Paste the contents in the test-input.json stored inside the service root directory.
-
Execute the npm test command.
> npm test
$ npm test
The test results are printed to the console:
> npm test
> jest
PASS moduleCicsCobol_itemdet/index.test.js
✓ itemdet test (529 ms)
console.log
{"dfhcommarea":{"itemNum":1001,"itemRecord":{"itemName":"Ball Pool","description":"Ball Pool - Novelty Toys","weight":100},"shipping":{"shippingMethod":"AIR MAIL","days":2}}}
at Object.<anonymous> (moduleCicsCobol_itemdet/index.test.js:10:13)
console.log
[
[ 'Input: \n', '{\n "dfhcommarea": {\n "itemNum": 1001\n }\n}' ],
[ 'Output: \n', { dfhcommarea: [Object] } ]
]
at Object.<anonymous> (moduleCicsCobol_itemdet/index.test.js:11:13)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 2.599 s, estimated 4 s
Ran all test suites.
Step 4: Deploy to Azure Function
After successfully testing the local Node.js Azure Function project, you can finally deploy the project to the Node.js Azure Function platform from the Azure CLI.
Updated 4 months ago