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
    Scroll to view full table
  • ibmcloud ce command:
    $ ibmcloud ce application update --name APP_NAME -p 8081
    Scroll to view full table

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
Scroll to view full table

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'
Scroll to view full table

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. 

More from Cloud

Modernizing child support enforcement with IBM and AWS

7 min read - With 68% of child support enforcement (CSE) systems aging, most state agencies are currently modernizing them or preparing to modernize. More than 20% of families and children are supported by these systems, and with the current constituents of these systems becoming more consumer technology-centric, the use of antiquated technology systems is archaic and unsustainable. At this point, families expect state agencies to have a modern, efficient child support system. The following are some factors driving these states to pursue modernization:…

7 min read

IBM Cloud Databases for Elasticsearch End of Life and pricing changes

2 min read - As part of our partnership with Elastic, IBM is announcing the release of a new version of IBM Cloud Databases for Elasticsearch. We are excited to bring you an enhanced offering of our enterprise-ready, fully managed Elasticsearch. Our partnership with Elastic means that we will be able to offer more, richer functionality and world-class levels of support. The release of version 7.17 of our managed database service will include support for additional functionality, including things like Role Based Access Control…

2 min read

Connected products at the edge

6 min read - There are many overlapping business usage scenarios involving both the disciplines of the Internet of Things (IoT) and edge computing. But there is one very practical and promising use case that has been commonly deployed without many people thinking about it: connected products. This use case involves devices and equipment embedded with sensors, software and connectivity that exchange data with other products, operators or environments in real-time. In this blog post, we will look at the frequently overlooked phenomenon of…

6 min read

SRG Technology drives global software services with IBM Cloud VPC under the hood

4 min read - Headquartered in Ft. Lauderdale, Florida, SRG Technology LLC. (SRGT) is a software development company supporting the education, healthcare and travel industries. Their team creates data systems that deliver the right data in real time to customers around the globe. Whether those customers are medical offices and hospitals, schools or school districts, government agencies, or individual small businesses, SRGT addresses a wide spectrum of software services and technology needs with round-the-clock innovative thinking and fresh approaches to modern data problems. The…

4 min read