The IBM Open Enterprise SDK for Node.js 22.0 is now available as a container image for z/OS Container Platform. This allows you to run your Node.js workloads in a container environment to streamline Node.js deployment, increase scalability, and improve workload management.
This blog teaches you how to run a sample Node.js application within a container:
Prerequisites
- z/OS System with z/OS Container Platform installed
- SMP/E licenses for the Open Enterprise SDK for Node.js and z/OSCP that come with their respective entitlement keys
- Entitlement keys should be found in the entitlement memo attached with your ShopZ order
Obtaining the Node.js container images
To obtain the Node.js images, run the following commands:
podman pull icr.io/zoscp/node:latest --creds iamapikey:<node.js image entitlement key>
Run a sample Node.js application within the Node.js container image
To start, create a new directory to set up your Node.js application:
$ mkdir app
$ cd app
$ npm init --yes
$ npm install express
Next, create an index.js file containing a simple Express.js application:
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
});
app.listen(port, () => {
console.log(`Example app listening on port ${port}`);
});
Afterwards, create a file named Containerfile containing the following instructions in order to containerize your application:
FROM node:latest
# Set production environment.
ENV NODE_ENV=production
# Set Node.js environment.
RUN . /node/.env
# Set application directory.
WORKDIR /app
# Copy package.json and package-lock.json.
COPY package*.json ./
# Install application dependencies.
RUN npm ci
# Copy the rest of the application.
COPY . .
# Enable network communication (3000 is the default port for Express.js).
EXPOSE 3000
# Start the application.
CMD ["node", "index.js"]
Finally, build and run the container with:
$ podman build -t app .
$ podman run -it app
Your application should now be running and listening on port 3000.
Expand the Node.js container with other containers
The Node.js container image is minimized to improve agility. This means the container image does not include additional tools such as C/C++ for Open Enterprise Languages for z/OS (5655-COE), which is required to compile Node.js native addons. Another example is the utility tools provided by IBM Open Enterprise Foundation for z/OS (5655-OEF).
The C/C++ for Open Enterprise Languages for z/OS is available in the Open Enterprise SDK for Python container image, and the Open Enterprise Foundation for z/OS products are available with the OEF container image. Both tools can be deployed together with the Node.js container.
To start, ensure that you have already obtained the Node.js, Python, and OEF container images.
Next, create a file named Containerfile containing the following instructions:
FROM python AS python
FROM node AS node
FROM oeftools
WORKDIR /
# Include C/C++.
COPY --from=python /usr/lpp/IBM/oelcpp /usr/lpp/IBM/oelcpp
# Include Python.
COPY --from=python /python /python
# Include Node.js.
COPY --from=node /node /node
# Set Python and C/C++ environment variables.
ENV PATH="$PATH:/usr/lpp/IBM/oelcpp/v2r0/bin:/python/bin"
ENV LIBPATH="$LIBPATH:/python/lib"
ENV LDSHARED="/usr/lpp/IBM/oelcpp/v2r0/bin/clang"
ENV TERMINFO="/python/share/terminfo"
# Set Node.js environment.
ENV NODE_ENV=production
RUN . /node/.env
# Set application directory.
WORKDIR /app
# Initialize a new application.
RUN npm init --yes
# Build a C/C++ native addon.
RUN npm install vsam.js
# Start the shell.
CMD ["bash"]
Finally, build and run the container with:
$ podman build -t app .
$ podman run -it app
You should now have a container that includes Node.js, Python, as well as C/C++, with the vsam.js native Node.js addon successfully built. Additional work can now be performed with the container.