The Node.js GCP Function Node Generator Guide
Overview
The Node.js GCP Function generator lets you set up and deploy an OpenLegacy service running on Node.js in the GCP 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 GCP Function service from an OpenLegacy hub project.
- Build the service as a Node.js GCP Function project.
- Test the new Node.js GCP Function project locally.
- Finally, deploy the project to GCP Function.
Prerequisites
Satisfy the following prerequisites:
- Install NPM v6 or later.
- Install Node.js v12 or later.
- Create a Google Cloud Platform account with a configured GCP project.
- Install GCP CLI.
Step 1: Generate a GCP 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 AWS service supports services 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 gcp-nodejs-function
$ ol generate --project "your_project_name" --generator gcp-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 into 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 GCP Function Project
After successfully building the Node.js application, you can test how it handles requests before deploying it to GCP.
- 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
console.log
Status: 200, Body: {"dfhcommarea":{"itemNum":1001,"itemRecord":{"itemName":"Ball Pool","description":"Ball Pool - Novelty Toys","weight":100},"shipping":{"shippingMethod":"AIR MAIL","days":2}}}
at Object.<anonymous> (test/index.test.js:11:13)
PASS test/index.test.js
✓ itemdet test (453 ms)
Test Suites: 1 passed, 1 total
Tests: 1 passed, 1 total
Snapshots: 0 total
Time: 2.356 s, estimated 3 s
Ran all test suites.
Step 4: Deploy to the Google Cloud Platform
After successfully testing the local Node.js GCP Function project, you can finally deploy the project to GCP using the GCP CLI.
Updated 4 months ago