addFlow() - TypeError: Cannot read property 'allNodes' of null

Hello,
I have just started using Node RED. I am creating an application where the user can send commands to the Raspberry PI and am using the RED Runtime Api. I am getting an error when using RED.nodes.addFlow()

\server\node_modules\node-red\red\runtime\nodes\flows\index.js:497
        if (activeFlowConfig.allNodes[node.id]) {
                             ^
TypeError: Cannot read property 'allNodes' of null

My server setup :

const express = require('express')
const bodyParser = require('body-parser')
const cors = require('cors')
const morgan = require('morgan')
var http = require('http')
var RED = require("node-red")
var app = express()
var server = http.createServer(app)
var settings = {
    httpAdminRoot:"/red",
    httpNodeRoot: "/api",
    userDir:"/home/nol/.nodered/",
    functionGlobalContext: { }    // enables global context
};
var nrFlow = {
    label: "Flow Label",
    nodes: [
    {
    	"id": "node-red/inject",
        "type": "inject",
        "name": "",
        "topic": "",
        "payload": "",
        "payloadType": "date",
        "repeat": "15",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "wires": [
        ]
    },
   ]
};
RED.init(server,settings);
RED.nodes.addFlow(nrFlow)
// Serve the editor UI from /red
app.use(settings.httpAdminRoot,RED.httpAdmin);
// Serve the http nodes UI from /api
app.use(settings.httpNodeRoot,RED.httpNode);
server.listen(8000);
RED.start()
app.use(morgan('combined'))
app.use(bodyParser.json())
app.use(cors())
app.get('/posts', (req, res) => {
  res.send(
    [{
      title: "Hello World!",
      description: "Hi there! How are you?",
      items : RED.nodes.getNodeConfigs()
    }]
  )
})
app.listen(process.env.PORT || 8081)

Any chance anyone could help me find the issue ? Thanks!

You cannot use the RED.nodes apis until the runtime has been started. You need to do that after the promise returned by RED.start() has resolved.