You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
<strong>(Edit: November 22, 2019) The Node images used in this post, both community <code>centos7</code> and <code>product</code>, are no longer being updated and maintained. For community images, please use the Universal Base Image (UBI)-based node images located here: <ahref="http://registry.access.redhat.com/ubi8/nodejs-10">registry.access.redhat.com/ubi8/nodejs-10</a></strong>
10
-
11
-
<strong>For a fully supported Product version of Node.js, please check out the Red Hat Software Collections Node.js image, <ahref="https://access.redhat.com/containers/#/registry.access.redhat.com/rhscl/nodejs-10-rhel7">RH SCL Node.js</a>.</strong>
12
-
13
10
With the recent <ahref="https://developers.redhat.com/blog/2018/03/12/rhoar-nodejs-annoucement/"target="_blank"rel="noopener noreferrer">announcement that Node.js is generally available as part of Red Hat OpenShift Application Runtimes,</a> I wanted to see how easy it was to deploy an <ahref="https://expressjs.com/">Express.js</a> app on OpenShift.
14
11
<h3>Getting Started</h3>
15
12
Before we start, there are some required prerequisites. You need to have <ahref="https://nodejs.org"target="_blank"rel="noopener noreferrer">Node 8.x</a> and <ahref="https://www.npmjs.com/"target="_blank"rel="noopener noreferrer">npm 5.2 </a> or greater installed. npm comes with the official node distribution, so if you install Node from <ahref="https://nodejs.org"target="_blank"rel="noopener noreferrer">Nodejs.org</a>, you should be good.
16
13
17
14
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 <ahref="https://developers.redhat.com/products/cdk/hello-world/"target="_blank"rel="noopener noreferrer">here</a>. For my local minishift, I start it with this command:
What is Express, you say? Well, according to the <ahref="https://expressjs.com/"target="_blank"rel="noopener noreferrer">Express website</a>, Express is a "Fast, unopinionated, minimalist web framework for Node.js."
27
30
28
31
One pretty cool thing about Express is the <i>Express application generator tool</i>: <code>express-generator</code>. This is a command-line tool that <ahref="https://expressjs.com/en/starter/generator.html">"quickly creates an application skeleton"</a>. But wait: didn't I just say that Express was unopinionated? It is, but this is the opinionated skeleton creator. ¯_(ツ)_/¯
29
32
30
33
The Express website recommends installing the <code>express-generator</code> module globally, like this:
31
-
<pre>npm install -g express-generator</pre>
34
+
35
+
`npm install -g express-generator`
36
+
32
37
But we aren't going to do that. Instead, we are going to use a fairly new feature from npm, called <code>npx</code>.
33
38
34
39
<code>npx</code> gives us the ability to run one-off commands with out having to install things globally. There is more to <code>npx</code> that just that feature, so if you are interested in all the cool things <code>npx</code> can do, check it out <ahref="https://medium.com/@maybekatz/introducing-npx-an-npm-package-runner-55f7d4bd282b">here</a>.
35
40
36
41
With this new-found knowledge, we can now generate our Express app like this:
37
-
<pre>$ npx express-generator .</pre>
42
+
43
+
`$ npx express-generator .`
44
+
38
45
Let's take a quick look at what is actually happening with this command. First, <code>npx</code> sees that we want to run the <code>express-generator</code> command, so <code>npx</code> 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.
39
46
40
-
<code>express-generator</code> is run in our current directory, which is denoted by that <strong>.</strong> at the end of the command.
47
+
<code>express-generator</code> is run in our current directory, which is denoted by that **.** at the end of the command.
41
48
42
49
The result should look something like this:
43
50
@@ -50,7 +57,9 @@ Now that we created our basic Express application using one command, we need to
50
57
We need to pass a <code>PORT</code> environment variable to our start script.
51
58
52
59
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 <ahref="https://www.npmjs.com/package/json"target="_blank"rel="noopener noreferrer">json module</a>.
Here, we are using the <ahref="https://www.npmjs.com/package/nodeshift"target="_blank"rel="noopener noreferrer">nodeshift module</a> to deploy our application. <code>nodeshift</code> is a CLI or programmable API that helps with deploying Node apps to OpenShift.
65
76
66
77
<code>npx</code> is doing the same thing as in the previous examples.
@@ -81,15 +92,25 @@ Then, if we click the link, we can see our example app running:
<strong>Note:</strong> The example above will use the latest <ahref="https://hub.docker.com/r/bucharestgold/centos7-s2i-nodejs/">community s2i images</a> (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.
95
+
__Note:__ The example above will use the latest <ahref="https://hub.docker.com/r/bucharestgold/centos7-s2i-nodejs/">community s2i images</a> (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.
85
96
86
97
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.
The example app we created was very simple, but it shows how quickly you can get started using Node.js on OpenShift.
113
+
114
+
_(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: <ahref="http://registry.access.redhat.com/ubi8/nodejs-10">registry.access.redhat.com/ubi8/nodejs-10</a>_
115
+
116
+
_For a fully supported Product version of Node.js, please check out the Red Hat Software Collections Node.js image, <ahref="https://access.redhat.com/containers/#/registry.access.redhat.com/rhscl/nodejs-10-rhel7">RH SCL Node.js</a>._
0 commit comments