Skip to main content
Redhat Developers  Logo
  • AI

    Get started with AI

    • Red Hat AI
      Accelerate the development and deployment of enterprise AI solutions.
    • AI learning hub
      Explore learning materials and tools, organized by task.
    • AI interactive demos
      Click through scenarios with Red Hat AI, including training LLMs and more.
    • AI/ML learning paths
      Expand your OpenShift AI knowledge using these learning resources.
    • AI quickstarts
      Focused AI use cases designed for fast deployment on Red Hat AI platforms.
    • No-cost AI training
      Foundational Red Hat AI training.

    Featured resources

    • OpenShift AI learning
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

    Red Hat AI Factory with NVIDIA

    • Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.
    • Explore the solution
  • Learn

    Self-guided

    • Documentation
      Find answers, get step-by-step guidance, and learn how to use Red Hat products.
    • Learning paths
      Explore curated walkthroughs for common development tasks.
    • Guided learning
      Receive custom learning paths powered by our AI assistant.
    • See all learning

    Hands-on

    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.
    • Interactive labs
      Learn by doing in these hands-on, browser-based experiences.
    • Interactive demos
      Click through product features in these guided tours.

    Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics

    Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
  • Build

    Get started

    • Red Hat build of Podman Desktop
      A downloadable, local development hub to experiment with our products and builds.
    • Developer Sandbox
      Spin up Red Hat's products and technologies without setup or configuration.

    Download products

    • Access product downloads to start building and testing right away.
    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset

    References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
  • Community

    Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions

    Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github

    Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

    Join the Red Hat Developer program

    • Download Red Hat products and project builds, access support documentation, learning content, and more.
    • Explore the benefits

Zero to Express on OpenShift in Three Commands

April 16, 2018
Lucas Holmquist
Related topics:
Node.js
Related products:
Red Hat OpenShift

    (Edit: November 22, 2019) The Node images used in this post, both community centos7 and product, are no longer being updated and maintained. For community images, please use the Universal Base Image (UBI)-based node images located here: registry.access.redhat.com/ubi8/nodejs-10

    For a fully supported Product version of Node.js, please check out the Red Hat Software Collections Node.js image, RH SCL Node.js.

    With the recent announcement that Node.js is generally available as part of Red Hat OpenShift Application Runtimes, I wanted to see how easy it was to deploy an Express.js app on OpenShift.

    Getting Started

    Before we start, there are some required prerequisites. You need to have Node 8.x and npm 5.2 or greater installed. npm comes with the official node distribution, so if you install Node from Nodejs.org, you should be good.

    You'll also need access to an OpenShift environment or the Red Hat Container Development Kit (CDK) minishift environment. For this example, I'll be using minishift. You can find instructions on getting minishift up and running here. For my local minishift, I start it with this command:

    $ minishift start --memory=6144 --vm-driver virtualbox

    You also need to be logged in to whatever OpenShift cluster you are using (OpenShift or minishift) using oc login.

    Spoiler Alert

    For those who don't want to read the whole post and don't want to scroll to the end, here are the three commands that need to be run:

    $ npx express-generator .
    $ npx json -I -f package.json -e 'this.scripts.start="PORT=8080 node ./bin/www"'
    $ npx nodeshift --strictSSL=false --expose

    Generate an Express App

    What is Express, you say? Well, according to the Express website, Express is a "Fast, unopinionated, minimalist web framework for Node.js."

    One pretty cool thing about Express is the Express application generator tool: express-generator. This is a command-line tool that "quickly creates an application skeleton". But wait: didn't I just say that Express was unopinionated? It is, but this is the opinionated skeleton creator. ¯_(ツ)_/¯

    The Express website recommends installing the express-generator module globally, like this:

    npm install -g express-generator

    But we aren't going to do that. Instead, we are going to use a fairly new feature from npm, called npx.

    npx gives us the ability to run one-off commands with out having to install things globally. There is more to npx that just that feature, so if you are interested in all the cool things npx can do, check it out here.

    With this new-found knowledge, we can now generate our Express app like this:

    $ npx express-generator .

    Let's take a quick look at what is actually happening with this command. First, npx sees that we want to run the express-generator command, so npx does some magic to see if we have it installed locally (in our current directory), and then it checks our global modules. Because it is not there, it downloads it for this one-time use.

    express-generator is run in our current directory, which is denoted by that . at the end of the command.

    The result should look something like this:

    express-generator also gives us some instructions on how to install the dependencies and then how to run the application. You can skip that for now.

    Update the package.json File

    Now that we created our basic Express application using one command, we need to add one thing to package.json before we deploy our app.

    We need to pass a PORT environment variable to our start script.

    One way to do this is to open a text editor and do it that way, but that would add a few more steps. To do this in one command, we can use the json module.

    $ npx json -I -f package.json -e 'this.scripts.start="PORT=8080 node ./bin/www"'

    As before, we are using the npx command to allow us to not have to install the json module globally.

    Let's see what is going on with the options passed to the json module.

    -I -f package.json means that we want to edit in place the file package.json. The -e option will execute some JavaScript code, which in this case is setting the scripts.start property from package.json with the string "PORT=8080 node ./bin/www".

    For more information on the json module, check out the documentation.

    Deploy the Application to OpenShift

    And now, the final step is to run this command:

    $ npx nodeshift --strictSSL=false --expose

    Here, we are using the nodeshift module to deploy our application. nodeshift is a CLI or programmable API that helps with deploying Node apps to OpenShift.

    npx is doing the same thing as in the previous examples.

    nodeshift is using two flags. The first, strictSSL=false, is needed when deploying to minishift or someplace that is using a self-signed certificate. If we were deploying to a real OpenShift cluster, we could leave that out.

    The second flag, expose, tells nodeshift that it should create a route for us, which allows our application to be seen by the outside world. (If you are running minishift locally, only you can see the application.)

    The output of this command will look something like this:

    If we head over to the web UI of our running minishift, we can see that the created pod is now running successfully.

    Then, if we click the link, we can see our example app running:

    Note: The example above will use the latest community s2i images (9.x at the time of this writing). To use a fully supported version of Node.js on OpenShift all you need is to add the "--dockerImage" flag.

    This will integrate the Red Hat OpenShift Application Runtime version Node.js (8.x) which you can get full production and developer support as part of our product subscription.

    This might look something like this:

    $ npx nodeshift --strictSSL=false --expose --dockerImage=registry.access.redhat.com/rhoar-nodejs/nodejs-8

    Recap

    In this post, the commands were a little spread out, so let's see them all together again:

    $ npx express-generator .
    $ npx json -I -f package.json -e 'this.scripts.start="PORT=8080 node ./bin/www"'
    $ npx nodeshift --strictSSL=false --expose

    The example app we created was very simple, but it shows how quickly you can get started using Node.js on OpenShift.

    Last updated: January 12, 2024

    Recent Posts

    • Every layer counts: Defense in depth for AI agents with Red Hat AI

    • Fun in the RUN instruction: Why container builds with distroless images can surprise you

    • Trusted software factory: Building trust in the agentic AI era

    • Build a zero trust AI pipeline with OpenShift and RHEL CVMs

    • Red Hat Hardened Images: Top 5 benefits for software developers

    Red Hat Developers logo LinkedIn YouTube Twitter Facebook

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    RED HAT DEVELOPER

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility

    Chat Support

    Please log in with your Red Hat account to access chat support.