Node Red is a very interesting topic for all kinds developers.
This is a Flow based development tool for visual coding, which is powered by npm packages.
UI / Backend / BPM / IoT / ML / BC all kind of developments you can do using Node-Red.
Here are the steps what you can follow run Node-Red in Cloud Foundry Environment:
Step 1: Open VS Code and run - "
npm init" in Terminal.
Step 2: Install two packages: "
node-red" and "
node-pre-gyp"
Step 3: Now navigate to the file -
red.js. Then add the line of code as added there from line 44-58.
This piece of code will help to implement the authentication on the top of the Node-Red Application.
Here is the sample of the code -
// Added by Sabarna Chatterjee//////////////////////////////////////////////////////////////////
app.use((req, res, next) => {
const auth = {login: 'UserName', password: 'PassWord'} // change this
const b64auth = (req.headers.authorization || '').split(' ')[1] || ''
const [login, password] = Buffer.from(b64auth, 'base64').toString().split(':')
// Verify login and password are set and correct
if (login && password && login === auth.login && password === auth.password) {
// Access granted...
return next()
}
// Access denied...
res.set('WWW-Authenticate', 'Basic realm="401"') // change this
res.status(401).send('Check Username and Password') // custom message
})
////////////////////////////////////////////////////////////////////
Step 4: Then we need to do some changes in the package.json file. As we need to default the initial load to
"./node_modules/node-red/red.js". The package.json will be as the given in this file
{
"name": "nodered",
"version": "1.0.0",
"description": "Node Red in SAP Cloud Foundry",
"scripts": {
"start": "node ./node_modules/node-red/red.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Sabarna Chatterjee",
"license": "ISC",
"dependencies": {
"node-pre-gyp": "^0.15.0",
"node-red": "^1.1.3"
}
}
Step 5: Now it's the time implement the manifest.yml file:
applications:
- name: nodeRedonSCPCF
random-route: true
path: ./
buidpack: https://github.com/cloudfoundry/nodejs-buidpack
host: nodeRedonSCPCF
memory: 128M
Now your package is ready to be pushed to cloud foundry. It you already know in detai regarding this please skip to
step 8 directly. Else follow accordingly.
Please install the cf_cli from
here.
Step 6: Goto cmd(for Debian - Terminal). Then execute the below command
cf7 login -a https://api.cf.eu10.hana.ondemand.com
Then give login credentials to proceed. Once you are logged in to your CF Account, it will appear as:

Step 7: Node lets Push it:
cf7 push -f C:\...\node-red-in-scp-cf\nodeRed\manifest.yml

Time to take a break. You can have a cup of coffee and come back inbetween.
In between your cmd will show something like this:


Step 8: Guys whoever directly came here from Step 5 - I know you already have been started to play with Node-Red. If not then please find what is restricting you till now.
Anyways, once the packed is deployed you need to just click a url to navigate to the Node-Red application:

And if you click in the correct url, a popup will appear where you need to enter login credentials. Feel free to use the below:
UserName , PassWord
As you already understand now why we have changed the actual red.js file.
Step 9: Here is a sample flow, which you can import and get started. You can refer to the link
here to see the steps in details.

Now click on deploy and start testing.
Step 10: Test your API using from POSTMAN.
You can save any JSON data using the
"/saveData" API. To do it, insert any json:
{
"cloud": "sap",
"software": "node-red",
"mode": "installation",
"by": "a Rockstar"
}
Execution of POST API(/saveData) -

Above inserted json can be retrieved by the below API.
Execution of GET API(/getData) -

Note -
- To use these API you need to pass the authentication details properly to the Node-Red API
- You can use internal authentications provided by SAP to the Node-Red application. for details, navigate here - Security
- For Dev, Quality, Production you can have three different instances of the same application in a same space.
- Have an api key inside your custom Node-Red design.
- You can use Business Application studio to perform all the setup activity as well.
- This setup which is described above is just for the developers. Please consult with an SME before you implement it for your project
At last I just want to conclude with some thoughts:
Node-Red is available for public from 2016. Its majorly popular in IoT-Raspberry PI spaces. But is has a capability to create applications for BPA(Business Process Automation). If you are going to design a too complex scenarios, use these Node-Red APIs. In the backend, you can easily integrate with
iRPA,
CAI-Chatbots,
SCP Cloud Workflow and design a very complex Business Process Solution easily.
Thanks for Reading.. ???
Please comment on your thoughts..
