March 22, 2021 By Kazuki Nobutani 2 min read

Three important tips to follow if you’re going to develop an app based on Node.js with IBM Cloud Code Engine.

IBM Cloud offers a new feature called IBM Cloud Code Engine — a fully managed, serverless platform that runs your containerized workloads, including web apps, microservices, event-driven functions or batch jobs. The Code Engine experience is designed so that you can focus on writing code and not on the infrastructure that is needed to host it.

In this blog, I will share what I learned through the development of an app based on Node.js. Some tips only apply to Node.js apps, and I assume you have reviewed Writing a Dockerfile for Code Engine already. 

Note: Code Engine is a beta service as of March 2021. This service might not yet be stable and is not for production use.

Prerequisites

1. Default port of Code Engine is 8080

 If you want to use non-default port other than 8080, specify the following line in the Dockerfile and run an `ibmcloud ce` command to change the port:

  • In Dockerfile:
    EXPOSE 8081
  • ibmcloud ce command:
    $ ibmcloud ce application update --name APP_NAME -p 8081

2. Make sure you have npm install in Dockerfile

This is a Node.js-specific practice. It is always safe to specify this in Dockerfile:

RUN npm install

During development, npm install is often performed and the required dependencies are imported in the node_modules, which are stored in the Git repository root directly. In the Dockerfile, the COPY . . will then use those dependencies for the build steps in the Dockerfile. In Code Engine, the build starts with a fresh Git clone, and, therefore, the node_modules is missing. As a result, you might see an error like the one below upon deploying the app:

Mar 8 16:21:10 Code Engine APP-XXX-deployment-YYY 2021-03-08T05:21:07.096108821Z stderr F Error: Cannot find module 'ZZZZ'

3. Do not carry node_modules 

This is also a Node.js-specific practice and the goal is the same — to keep everything clean and tidy:

  • In the Git repository where your code exists, create .dockerignore and add node_modules to avoid the accidental pick-up of local files. Whatever is in this file won’t be included upon build.
  • In the Git repository, create .gitignore to avoid node_modules on git gets updated upon push.

The key takeaway here is that you should always have Tips 2 and 3 in your code so that you can prevent your Docker image from getting created based on the node_modules on the host side. Make sure npm install is executed inside the Docker image.

Having a trouble deploying an app? 

Please feel free to contact IBM client support for any questions or concerns. 

Was this article helpful?
YesNo

More from Cloud

New 4th Gen Intel Xeon profiles and dynamic network bandwidth shake up the IBM Cloud Bare Metal Servers for VPC portfolio

3 min read - We’re pleased to announce that 4th Gen Intel® Xeon® processors on IBM Cloud Bare Metal Servers for VPC are available on IBM Cloud. Our customers can now provision Intel’s newest microarchitecture inside their own virtual private cloud and gain access to a host of performance enhancements, including more core-to-memory ratios (21 new server profiles/) and dynamic network bandwidth exclusive to IBM Cloud VPC. For anyone keeping track, that’s 3x as many provisioning options than our current 2nd Gen Intel Xeon…

IBM and AWS: Driving the next-gen SAP transformation  

5 min read - SAP is the epicenter of business operations for companies around the world. In fact, 77% of the world’s transactional revenue touches an SAP system, and 92% of the Forbes Global 2000 companies use SAP, according to Frost & Sullivan.   Global challenges related to profitability, supply chains and sustainability are creating economic uncertainty for many companies. Modernizing SAP systems and embracing cloud environments like AWS can provide these companies with a real-time view of their business operations, fueling growth and increasing…

Experience unmatched data resilience with IBM Storage Defender and IBM Storage FlashSystem

3 min read - IBM Storage Defender is a purpose-built end-to-end data resilience solution designed to help businesses rapidly restart essential operations in the event of a cyberattack or other unforeseen events. It simplifies and orchestrates business recovery processes by providing a comprehensive view of data resilience and recoverability across primary and  auxiliary storage in a single interface. IBM Storage Defender deploys AI-powered sensors to quickly detect threats and anomalies. Signals from all available sensors are aggregated by IBM Storage Defender, whether they come…

IBM Newsletters

Get our newsletters and topic updates that deliver the latest thought leadership and insights on emerging trends.
Subscribe now More newsletters