Read this in other languages: 日本語.
Different ways to start a Node-RED instance, either locally, using MiniShift or using IBM Cloud.
Before you begin
Before setting up your environment, and in order to create the services needed for the workshop, you'll need an IBM Cloud account.
- Sign up for an account here
- Verify your account by clicking on the link in the email sent to you
- Log in to your IBM Cloud account
- Click on "Catalog" towards the top-right corner
- Select the "Software" tab
- Search and select "Node-RED App"
- Following the tutorial steps at developer.ibm.com for creating and deploying your Node-RED application.
** Note: ** make sure your application is assigned at least 256MB of runtime meory (the default will be 128MB, which is insufficient)
Once your app is deployed you'll be able to access it through the resource list
This requires having Minishift installed on your machine, if you don't you can follow a detailed guide here.
The OpenShift nodejs
cartridge documentation can be found at:
http://openshift.github.io/documentation/oo_cartridge_guide.html#nodejs
Open your terminal and run the following commands:
minishift --vm-driver=hyperkit start
(or equivalent, based on which vm you're using)eval $(minishift oc-env)
oc login -u developer
Clone the repository
Still using your terminal:
- Clone the starter repo using the following command:
git clone https://github.com/emarilly/openshift-node-red
- Change directory into the OpenShift-noe-red folder
cd openshift-node-red
Update package.json
Using your favorite IDE (we're not judging) open and edit the package.json
file:
- update the Node.js engine to current LTS (
>=10.0.0
) - update the NPM engine to be inline with node LTS (
>= 6.0.0
) - update Node-RED dependency to current levels (
>= 1.0
) - add a scripts section
"scripts": {
"build": "true",
"start": "node server.js"
},
Update server.js
Next, open and edit the server.js
file:
- comment out basic authentication setup
//setup basic authentication
//var basicAuth = require('basic-auth-connect');
//self.app.use(basicAuth(function(user, pass) {
// return user === 'test' && pass === atob('dGVzdA==');
//}));
- update local port to
8080
self.port = process.env.OPENSHIFT_NODEJS_PORT || 8080;
- update default ipaddress to "0.0.0.0"
self.ipaddress = process.env.OPENSHIFT_NODEJS_IP || "0.0.0.0";
Once this is all done, go back to your terminal and run the following command npm install
.
- Create a new app and give it a name (ie. myfirst-node-red)
oc new-app nodejs~./ --name=myfirst-node-red
- Start the build of your app
oc start-build myfirst-node-red --from-dir=./
- You can check the status at any time using
- run
oc status
- Once the build is complete, run the following command to get the service
oc get service myfirst-node-red
- Expose the service at a host name using:
oc expose service myfirst-node-red
All done! You can now access your Node-RED application running on Minishift using the response from oc get route/myfirst-node-red
NAME HOST/PORT PATH SERVICES PORT TERMINATION WILDCARD
myfirst-node-red myfirst-node-red-node-red.<aaa.bbb.ccc.ddd>.nip.io myfirst-node-red 8080-tcp None
- Open your browser to
http://myfirst-node-red-node-red.<aaa.bbb.ccc.ddd>.nip.io
Follow the instructions on the Node-RED website
You're all set and ready to go! Go back to the workshop page and follow the instructions there.
- When building your app to run on Minishift the build may fail on the first go, try running the following command again
oc start-build myfirst-node-red --from-dir=./